From 8aa3f94c9011a879bf6222b3517d4b713d94bb8d Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 26 Aug 2015 18:47:05 +0200 Subject: [PATCH] Drop stream state after stream error Fixes SMACK-696. --- .../smack/tcp/XMPPTCPConnection.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 afa817fc3..2cf635221 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 @@ -16,6 +16,7 @@ */ package org.jivesoftware.smack.tcp; +import org.jivesoftware.smack.AbstractConnectionListener; import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; @@ -295,6 +296,14 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) { super(config); this.config = config; + addConnectionListener(new AbstractConnectionListener() { + @Override + public void connectionClosedOnError(Exception e) { + if (e instanceof XMPPException.StreamErrorException) { + dropSmState(); + } + } + }); } /** @@ -402,7 +411,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // connection instance though). This is used in writePackets to decide if stanzas should // be added to the unacknowledged stanzas queue, because they have to be added right // after the 'enable' stream element has been sent. - unacknowledgedStanzas = null; + dropSmState(); } if (isSmAvailable() && useSm) { // Remove what is maybe left from previously stream managed sessions @@ -1707,6 +1716,17 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { } } + /** + * Drop the stream management state. Sets {@link #smSessionId} and + * {@link #unacknowledgedStanzas} to null. + */ + private void dropSmState() { + // clientHandledCount and serverHandledCount will be reset on and + // respective. No need to reset them here. + smSessionId = null; + unacknowledgedStanzas = null; + } + /** * Get the maximum resumption time in seconds after which a managed stream can be resumed. *