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 71b3172e0..8a24f038b 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 @@ -1349,6 +1349,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } private void writePackets() { + Exception writerException = null; try { openStream(); initalOpenStreamSend.reportSuccess(); @@ -1471,7 +1472,7 @@ 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())) { - notifyConnectionError(e); + writerException = e; } else { LOGGER.log(Level.FINE, "Ignoring Exception in writePackets()", e); } @@ -1479,6 +1480,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { LOGGER.fine("Reporting shutdownDone success in writer thread"); shutdownDone.reportSuccess(); } + // Delay notifyConnectionError after shutdownDone has been reported in the finally block. + if (writerException != null) { + notifyConnectionError(writerException); + } } private void drainWriterQueueToUnacknowledgedStanzas() {