ReconnetionManager ending without reconnecting


First of all, let me congratulate everybody working on the smack project.

I’m testing the smack library to make multiple connections to the Facebook Chat Server. Many connections drop after a while, sometimes the ReconnectionManager works, sometimes it doesn’t.

After sometime studying the logs, I think I finally have an idea of what might be happening:

There are 3 threads involved (the thread started at the PacketReader, the thread started at the PacketWriter and the thread started inside ReconnectionManger).

The first 2 threads (PacketReader, PacketWriter) behave the same way. Synchronized methods don’t allow them to have race conditions.

  1. The connection is lost, The thread started by the Packet Reader starts the reconnection manager which creates the reconnectionThread if there is none.

  2. The reconnectionThread will try to reconnect until it achives it’s goal (or other conditions which are not relevant right now).

  3. After some time, and while the reconnectionThread has made a number of attempts, the thread inside the **reader **has an exception (copied as APPENDIX 1), terminating the do while code inside ***private void parsePackets(Thread thread) ***.

Before terminating, the PacketReader notifies the listeners, executing first connectionClosed() (inside shutdown) and then connectionClosedOnError()

  • void notifyConnectionError(Exception e) {*

  •    done = true;*
  •    // Closes the connection temporary. A reconnection is possible*
  • ** connection.shutdown(new Presence(Presence.Type.unavailable));***

  •    // Print the stack trace to help catch the problem*
  •    e.printStackTrace();*
  •    // Notify connection listeners of the error.*
  •    for (ConnectionListener listener : connection.getConnectionListeners()) {*
  •        try {*
  •          **  listener.connectionClosedOnError(e);***
  •        }*
  •        catch (Exception e2) {*
  •            // Catch and print any exception so we can recover*
  •            // from a faulty listener*
  •            e2.printStackTrace();*
  •        }*
  •    }*
  • }*

The ReconnectionManager object receives the first notification but not the second one. In detail, ReconnectionManger#isReconnectionAllowed()

private boolean isReconnectionAllowed() {

return !done && !connection.isConnected()

&& connection.isReconnectionAllowed();


Keeps the done value true from ***connectionClosed(), ***never reconnecting again.

Any ideas?

Thanks in advance


*APPENDIX 1 * Unsupported record version Unknown-23.3




at 5)


at sun.nio.cs.StreamDecoder.readBytes(

at sun.nio.cs.StreamDecoder.implRead(





at org.xmlpull.mxp1.MXParser.fillBuf(

at org.xmlpull.mxp1.MXParser.more(

at org.xmlpull.mxp1.MXParser.parseProlog(

at org.xmlpull.mxp1.MXParser.nextImpl(


at org.jivesoftware.smack.PacketReader.parsePackets(

at org.jivesoftware.smack.PacketReader.access$1(

at org.jivesoftware.smack.PacketReader$

1 Like