From c3848495328bf6ebaf7de1adfe0e5c8685afa1f3 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 17 Jun 2020 20:34:36 +0200 Subject: [PATCH] Set 'running' to false before calling notifyConnectionError() Since the current variant of notifyConnectionError() does not execute most of its work in a new thread, especially since instantShutdown() is called in the invoking thread, we have to mark the connections reader or writer threads as no longer running prior them invoking notifyConnectionError(). Otherwise they will end up waiting for themselves to terminate. --- .../java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 558bacdf0..30785fdbc 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -1129,6 +1129,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // The exception can be ignored if the the connection is 'done' // or if the it was caused because the socket got closed. if (!done) { + // Set running to false since this thread will exit here and notifyConnectionError() will wait until + // the reader and writer thread's 'running' value is false. + running = false; // Close the connection and notify connection listeners of the // error. notifyConnectionError(e); @@ -1381,6 +1384,9 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // The exception can be ignored if the the connection is 'done' // or if the it was caused because the socket got closed if (!(done() || queue.isShutdown())) { + // Set running to false since this thread will exit here and notifyConnectionError() will wait until + // the reader and writer thread's 'running' value is false. + running = false; notifyConnectionError(e); } else { LOGGER.log(Level.FINE, "Ignoring Exception in writePackets()", e);