]> nmode's Git Repositories - signal-cli/commitdiff
Handle queued actions also when thread is interrupted
authorAsamK <asamk@gmx.de>
Mon, 23 Aug 2021 12:39:40 +0000 (14:39 +0200)
committerAsamK <asamk@gmx.de>
Mon, 23 Aug 2021 12:39:40 +0000 (14:39 +0200)
lib/src/main/java/org/asamk/signal/manager/Manager.java
src/main/java/org/asamk/signal/commands/DaemonCommand.java
src/main/java/org/asamk/signal/commands/JsonRpcDispatcherCommand.java
src/main/java/org/asamk/signal/commands/ReceiveCommand.java

index cc57e0614b27451a0864e19e19b70cc8b66d8f51..80c5fbbb3a7758886e04d980f58ca7966f54dee3 100644 (file)
@@ -1790,16 +1790,7 @@ public class Manager implements Closeable {
                 queuedActions.addAll(actions);
             }
         }
-        for (var action : queuedActions) {
-            try {
-                action.execute(this);
-            } catch (Throwable e) {
-                if (e instanceof AssertionError && e.getCause() instanceof InterruptedException) {
-                    Thread.currentThread().interrupt();
-                }
-                logger.warn("Message action failed.", e);
-            }
-        }
+        handleQueuedActions(queuedActions);
     }
 
     private List<HandleAction> retryFailedReceivedMessage(
@@ -1843,7 +1834,7 @@ public class Manager implements Closeable {
             boolean returnOnTimeout,
             boolean ignoreAttachments,
             ReceiveMessageHandler handler
-    ) throws IOException, InterruptedException {
+    ) throws IOException {
         retryFailedReceivedMessages(handler, ignoreAttachments);
 
         Set<HandleAction> queuedActions = new HashSet<>();
@@ -1875,16 +1866,7 @@ public class Manager implements Closeable {
                     // Received indicator that server queue is empty
                     hasCaughtUpWithOldMessages = true;
 
-                    for (var action : queuedActions) {
-                        try {
-                            action.execute(this);
-                        } catch (Throwable e) {
-                            if (e instanceof AssertionError && e.getCause() instanceof InterruptedException) {
-                                Thread.currentThread().interrupt();
-                            }
-                            logger.warn("Message action failed.", e);
-                        }
-                    }
+                    handleQueuedActions(queuedActions);
                     queuedActions.clear();
 
                     // Continue to wait another timeout for new messages
@@ -1892,7 +1874,8 @@ public class Manager implements Closeable {
                 }
             } catch (AssertionError e) {
                 if (e.getCause() instanceof InterruptedException) {
-                    throw (InterruptedException) e.getCause();
+                    Thread.currentThread().interrupt();
+                    break;
                 } else {
                     throw e;
                 }
@@ -1970,6 +1953,20 @@ public class Manager implements Closeable {
                 }
             }
         }
+        handleQueuedActions(queuedActions);
+    }
+
+    private void handleQueuedActions(final Set<HandleAction> queuedActions) {
+        for (var action : queuedActions) {
+            try {
+                action.execute(this);
+            } catch (Throwable e) {
+                if (e instanceof AssertionError && e.getCause() instanceof InterruptedException) {
+                    Thread.currentThread().interrupt();
+                }
+                logger.warn("Message action failed.", e);
+            }
+        }
     }
 
     private boolean isMessageBlocked(
index 494892930eec05576c19d616e6e3360bc47fb1ae..0591486c931f80b85450ae136fd74b24a6cbaeff 100644 (file)
@@ -134,8 +134,6 @@ public class DaemonCommand implements MultiLocalCommand {
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
-                } catch (InterruptedException ignored) {
-                    break;
                 }
             }
         });
index 6b5361e5b7943251956fdf0171219de4af321c14..16d0cf717621e03aa50f9655423cfcd56579f8a5 100644 (file)
@@ -168,8 +168,6 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
-                } catch (InterruptedException e) {
-                    break;
                 }
             }
         });
index 82bd5d8f274f5c2f21d9173d02dc08ada8ced7c7..f248d6628d9a34fa6cf988e840862a04dcb2bcbd 100644 (file)
@@ -158,7 +158,6 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
                     handler);
         } catch (IOException e) {
             throw new IOErrorException("Error while receiving messages: " + e.getMessage());
-        } catch (InterruptedException ignored) {
         }
     }
 }