Skip to content

Commit

Permalink
(#781) Filter out InterruptedExceptions coming into RxJava onError ha…
Browse files Browse the repository at this point in the history
…ndler inside RuntimeExceptions.

When you dispose of RxJava reactive stream it interrupts whatever blocking operation current running so they throw InterruptedException. If it so happens that we do a sync DB call via runTask() inside
RxJava stream and it gets terminated runTask will throw a RuntimeException with InterruptedException inside it.
  • Loading branch information
K1rakishou committed Mar 1, 2020
1 parent 7573246 commit 16b0a14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void onCreate() {
// fine, some blocking code was interrupted by a dispose call
return;
}
if (e instanceof RuntimeException && e.getCause() instanceof InterruptedException) {
// fine, DB synchronous call (via runTask) was interrupted when a reactive stream
// was disposed of.
return;
}
if (e instanceof FileCacheException.CancellationException
|| e instanceof FileCacheException.FileNotFoundOnTheServerException) {
// fine, sometimes they get through all the checks but it doesn't really matter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ public <T> void runTaskAsync(final Callable<T> taskCallable, final TaskResult<T>
public <T> T runTask(final Callable<T> taskCallable) {
try {
return executeTask(taskCallable, null).get();
} catch (InterruptedException | ExecutionException e) {
} catch (InterruptedException e) {
// Since we don't rethrow InterruptedException we need to at least restore the
// "interrupted" flag.
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 16b0a14

Please sign in to comment.