powered by Jive Software

Bug in smack reconnection?

I think I have found a bug in smack that causes the reconnection manager to give up without getting a connection in certain circumstances. I have looked at the issue list, but I can’t find anything that exactly matches this problem.

The problem is this: In ReconnectionManager.isReconnectionAllowed, there is a check for connection.packetReader != null. In XMPPConnection.initConnection, at line 981, packetReader is set to null if an exception occurs during connection.

This means that if an exception occurs in initConnection while reconnecting, the ReconnectionManager thread gives up and stops trying to reconnect.

This bug can be reproduced easily using this “server”:

public class TestServer
{
public static void main(String[] args) throws Exception
{
ServerSocket server = new ServerSocket(5222);
for (;:wink:
{
final Socket socket = server.accept();
System.out.println(“Accepted connection from [” + socket.getRemoteSocketAddress() + “]”);

Thread t = new Thread()
{
@Override
public void run()
{
try
{
InputStream stream = socket.getInputStream();
stream.read();
stream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
};

t.start();
}
}
}

To reproduce, first start a proper server and connect to it. Then kill the real server and start the test server instead. When smack attempts to connect to the test server, the ReconnectionManager gives up after a few seconds.