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 cd4e320c6..20d9e4495 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 @@ -399,8 +399,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { LOGGER.fine("Stream resumption failed, continuing with normal stream establishment process"); } - bindResourceAndEstablishSession(resource); - List previouslyUnackedStanzas = new LinkedList(); if (unacknowledgedStanzas != null) { // There was a previous connection with SM enabled but that was either not resumable or @@ -413,6 +411,12 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // after the 'enable' stream element has been sent. dropSmState(); } + + // Now bind the resource. It is important to do this *after* we dropped an eventually + // existing Stream Management state. As otherwise and may end up in + // unacknowledgedStanzas and become duplicated on reconnect. See SMACK-706. + bindResourceAndEstablishSession(resource); + if (isSmAvailable() && useSm) { // Remove what is maybe left from previously stream managed sessions serverHandledStanzasCount = 0;