Hello,
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.
-
The connection is lost, The thread started by the Packet Reader starts the reconnection manager which creates the reconnectionThread if there is none.
-
The reconnectionThread will try to reconnect until it achives it’s goal (or other conditions which are not relevant right now).
-
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
Alejandro
*APPENDIX 1 *
javax.net.ssl.SSLException: Unsupported record version Unknown-23.3
at com.sun.net.ssl.internal.ssl.InputRecord.readV3Record(InputRecord.java:375)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:360)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:75 5)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.read1(BufferedReader.java:185)
at java.io.BufferedReader.read(BufferedReader.java:261)
at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2992)
at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)
at org.jivesoftware.smack.PacketReader.access$1(PacketReader.java:220)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)