powered by Jive Software

Disconnect with error doesn't trigger stream resume


I’m using Smack 4.4.2 and I noticed that a connection drop causes an exception to be raised:

2021-04-14 11:46:05.628 30382-31044/com.wit.mpesa.chat E/SmackAndroidLogger: XMPPConnection closed due to an exception (XMPPTCPConnection[REDACTED] (0))
    java.net.SocketException: Software caused connection abort
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:119)
        at java.net.SocketInputStream.read(SocketInputStream.java:176)
        at java.net.SocketInputStream.read(SocketInputStream.java:144)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:351)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:180)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.read1(BufferedReader.java:221)
        at java.io.BufferedReader.read(BufferedReader.java:297)
        at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:42)
        at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1516)
        at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:993)
        at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)
        at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
        at org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParser.next(Xpp3XmlPullParser.java:228)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1140)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:913)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:936)
        at java.lang.Thread.run(Thread.java:764)

This will trigger a notifyConnectionError to be called, which in turn will call instantShutdown.

Looking at the code:

Notice the “missing return here?”. Given the code comments, shouldn’t be a return there? My stream is always reverting to “connected = false” which makes it impossible to reconnect again without losing the sessionId.

Am I doing something wrong?

The comment “If we are able to resume…” is definetly wrong (probably outdated). That said, as long as smSessionId is set, isSmResumptionPossible() should return true (if the other conditions apply).

Your post’s title reads “Disconnect with error doesn’t trigger stream resume”. Now that’s a slightly different topic. If you look at the code, then you will find that notifyConnectionError() does call instantShutdown(), which, while terminating the connection, does preserve the Stream Management state, and that includes smSessionId.

So I don’t see how a disconnect with error prevents stream resumption. But maybe I’ve missed something?

Because the connection is marked as “connected = false”. Which means I need to call connect again and that will always reset the sessionID:


Doesn’t that mean that the reconnect will fail? Or is that different from the smSessionId?

So I just checked and yes, you’re correct. There should be no issues with the reconnect from SM if we have to call connect again.

This was an issue from my side.

1 Like

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.