From 230a226424e4219f07cffe3f0130ce67fa830b0e Mon Sep 17 00:00:00 2001 From: Dmitry Deshevoy Date: Thu, 16 Nov 2017 17:30:16 +0300 Subject: [PATCH] Prevent race condition after stream resumption New stanzas sent directly after stream resumption might have been added to unacknowledgedStanzas before the old unacknowledged stanzas are resent. This caused new stanzas to be sent twice and later led to a StreamManagementCounterError. Fixes SMACK-786 --- .../java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 c604dc675..0c33aae1c 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 @@ -1155,8 +1155,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { if (!smSessionId.equals(resumed.getPrevId())) { throw new StreamIdDoesNotMatchException(smSessionId, resumed.getPrevId()); } - // Mark SM as enabled and resumption as successful. - smResumedSyncPoint.reportSuccess(); + // Mark SM as enabled smEnabledSyncPoint.reportSuccess(); // First, drop the stanzas already handled by the server processHandledCount(resumed.getHandledCount()); @@ -1172,6 +1171,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { if (!stanzasToResend.isEmpty()) { requestSmAcknowledgementInternal(); } + // Mark SM resumption as successful + smResumedSyncPoint.reportSuccess(); LOGGER.fine("Stream Management (XEP-198): Stream resumed"); break; case AckAnswer.ELEMENT: