Stucked in infinite loop in parsePackets()

When XMPPTCPConnection is interrupted internally (i.e. socket exception when connection was lost) PacketReader get stuck in infinite loop and this is log in logcat every few millis : “W/XMPPTCPConnection﹕ Got END_DOCUMENT, aborting parsing”

I have never seen this issue while I was using alpha-4. On October 21 Flow made this commit Don’t check for END_DOCUMENT parsePackets() · 5f9c342 · igniterealtime/Smack · GitHub

So now when I reach the END_DOCUMENT sign disconnect() is called. But problem appears in case that I get END_DOCUMENT but I am not connected yet! As you can see on disconnect method below shutdown() is never called in case we are not connected. So it leads to infinite loop and the PacketReader thread is never interrupted.

public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException {

if (!isConnected()) {







To fix this issue I suggest to throw NotConnectedException from disconnect() method in case that we are not connected instead of just returning. It would solve my issue and I think it would not cause any other problems.


P.S. My code was working fine until I updated smack from 4.1.0-alpha4 to 4.1.0-alpha5. I am using Stream management.

Excellent bug report. But I think the analysis is not 100% correct. The main problem was that the ‘break’ statement in the END_DOCUMENT case should break the parsing loop and not the switch/case. I’m going with a loop label and using instantShutdown(). It still makes sense to change the return to throw for consistency.

I am glad I was able to help! When do you think will be available next version of the library with this bug fixed?


The latest published 4.1.0-alpha6-SNAPSHOTS already contain the fix. But they also change the ConnectionConfiguration API a bit.