From b7465e820002aee48ce2ba37b54ceb45bc48b199 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 31 May 2020 14:15:13 +0200 Subject: [PATCH] [tcp] Do not needlessly wait for closing stream tag --- .../smack/tcp/XMPPTCPConnection.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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 0980d00b2..361eb2255 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 @@ -477,14 +477,19 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } private void shutdown(boolean instant) { - // First shutdown the writer, this will result in a closing stream element getting send to - // the server - LOGGER.finer("PacketWriter shutdown()"); - packetWriter.shutdown(instant); - LOGGER.finer("PacketWriter has been shut down"); + // The writer thread may already been finished at this point, for example when the connection is in the + // disconnected-but-resumable state. There is no need to wait for the closing stream tag from the server in this + // case. + if (!packetWriter.done()) { + // First shutdown the writer, this will result in a closing stream element getting send to + // the server + LOGGER.finer("PacketWriter shutdown()"); + packetWriter.shutdown(instant); + LOGGER.finer("PacketWriter has been shut down"); - if (!instant) { - waitForClosingStreamTagFromServer(); + if (!instant) { + waitForClosingStreamTagFromServer(); + } } LOGGER.finer("PacketReader shutdown()");