From 16b0a14097f23cf2f52069e69655c4583b3dc79e Mon Sep 17 00:00:00 2001 From: k1rakishou Date: Sun, 1 Mar 2020 21:10:42 +0300 Subject: [PATCH] (#781) Filter out InterruptedExceptions coming into RxJava onError handler 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. --- .../src/main/java/com/github/adamantcheese/chan/Chan.java | 5 +++++ .../adamantcheese/chan/core/database/DatabaseManager.java | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/Chan.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/Chan.java index dad5e843c3..7a7891a4c2 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/Chan.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/Chan.java @@ -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 diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/database/DatabaseManager.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/database/DatabaseManager.java index 626334e1c6..350e6c1ae2 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/database/DatabaseManager.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/database/DatabaseManager.java @@ -207,7 +207,12 @@ public void runTaskAsync(final Callable taskCallable, final TaskResult public T runTask(final Callable 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); } }