powered by Jive Software

Smack 4.2.0-rc2 ReconnectionManager does not return its status to ConnectionListener

aTalk has JabberConnectionListener() class implementation for smack ConnectionLister, it is also configured to use Smack 4.2.0-rc2 ReconnectionManager. During account login process, the JabberConnectionListener is registered with the XMPPTCPConnection just prior to making actual xmpp connect().

/* Start monitoring the status before connection-login. Only register listener once */
mConnection = new XMPPTCPConnection(config.build());

if (connectionListener == null) {
connectionListener = new JabberConnectionListener();
mConnection.addConnectionListener(connectionListener);
}

Upon successfully network connection, JabberConnectionListener#connected() method then proceeds to register ConnectionManager using mConnection.

JabberConnectionListener()#connected(XMPPConnection connection)

{

======= following two statements are actually called via sub-routine, hence it uses mConnection instead of connection ===========

ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
reconnectionManager.enableAutomaticReconnection();

}

All the callback methods of the JabberConnectionListener are working as expected in the whole login in process until authenticated => network lost.

When I simulated a network lost, the connectionClosedOnError(Exception exception)

is also get triggered as shown in bold in the log file, and the ReconnectionManager reconnect attempt is also working correctly as seen from the log file.

When the network is again resumed, the ReconnectionManager does make a successful re-connection to the network and resume with the server. However the problem is, all the status of the ReconnectionManager in the reconnection process are not reported back to the JabberConnectionListener() and the application is unaware on successful server re-connect. When the application get triggered by other event, it founds that it is still in the unregistration state when the network is lost, so it sends an presence-unavailable to the server.

Is there something I have left out, that causes the JabberConnectionListener() not being informed of the ReconnectionManager reconnection status.

I checked through the ConnectionManager source, but cannot see a way I can register JabberConnectionListener with the ReconnectionManager.

=================== Smack log with simulatate network lost and resume

01-13 14:59:45.527 org.atalk.android W/αTalk: [6] org.jivesoftware.smack.AbstractXMPPConnection.callConnectionClosedOnErrorListen er() Connection XMPPTCPConnection[leopard@atalk.org/atalk] (0) closed with error

javax.net.ssl.SSLException: Read error: ssl=0xaee21600: I/O error during system call, Connection timed out

at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)

at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketIm pl.java:728)

at java.io.InputStreamReader.read(InputStreamReader.java:231)

at java.io.BufferedReader.read(BufferedReader.java:325)

at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)

at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515)

at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1227)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:995)

at java.lang.Thread.run(Thread.java:818)

01-13 14:59:45.537 org.atalk.android E/αTalk: [6] impl.protocol.jabber.ProtocolProviderServiceJabberImpl.connectionClosedOnError( ).1286 connection Closed OnError: Read error: ssl=0xaee21600: I/O error during system call, Connection timed out

javax.net.ssl.SSLException: Read error: ssl=0xaee21600: I/O error during system call, Connection timed out

at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)

at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketIm pl.java:728)

at java.io.InputStreamReader.read(InputStreamReader.java:231)

at java.io.BufferedReader.read(BufferedReader.java:325)

at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)

at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515)

at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1227)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:995)

at java.lang.Thread.run(Thread.java:818)

01-13 14:59:45.667 org.atalk.android D/SMACK: XMPPConnection closed (XMPPTCPConnection[leopard@atalk.org/atalk] (0))

01-13 14:59:45.667 org.atalk.android D/SMACK: XMPPConnection closed due to an exception (XMPPTCPConnection[leopard@atalk.org/atalk] (0))

javax.net.ssl.SSLException: Read error: ssl=0xaee21600: I/O error during system call, Connection timed out

at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)

at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketIm pl.java:728)

at java.io.InputStreamReader.read(InputStreamReader.java:231)

at java.io.BufferedReader.read(BufferedReader.java:325)

at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)

at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515)

at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)

at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPC onnection.java:1227)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPCon nection.java:980)

at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnecti on.java:995)

at java.lang.Thread.run(Thread.java:818)

01-13 14:59:46.357 org.atalk.android I/αTalk: [1] impl.sysactivity.SystemActivityNotificationsServiceImpl.fireSystemActivityEvent ().489 Received system activity event: net.java.sip.communicator.service.sysactivity.event.SystemActivityEvent[eventID =9]

01-13 14:59:46.677 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 3

01-13 14:59:47.677 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 2

01-13 14:59:48.677 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 1

01-13 14:59:49.677 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 0

01-13 14:59:49.677 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 0

01-13 14:59:54.977 org.atalk.android D/SMACK: Reconnection failed due to an exception (XMPPTCPConnection[leopard@atalk.org/atalk] (0))

org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: ‘atalk.sytes.net:5222’ failed because: de.measite.minidns.util.MultipleIoException: sendto failed: ENETUNREACH (Network is unreachable), failed to connect to /192.168.1.254 (port 53) after 5000ms: connect failed:

01-13 15:00:33.327 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 3

01-13 15:00:34.327 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 2

01-13 15:00:35.337 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 1

01-13 15:00:36.337 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 0

01-13 15:00:36.337 org.atalk.android D/SMACK: XMPPConnection (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) will reconnect in 0

01-13 15:00:38.107 org.atalk.android I/αTalk: [1] impl.sysactivity.SystemActivityNotificationsServiceImpl.fireSystemActivityEvent ().489 Received system activity event: net.java.sip.communicator.service.sysactivity.event.SystemActivityEvent[eventID =9]

01-13 15:00:42.087 org.atalk.android D/SMACK: SENT (0): <stream:stream xmlns=‘jabber:client’ to=‘atalk.org’ xmlns:stream=‘http://etherx.jabber.org/streams’ version=‘1.0’ xml:lang=‘en’>

01-13 15:00:42.087 org.atalk.android D/SMACK: RECV (0): <?xml version='1.0'?><stream:stream xmlns=‘jabber:client’ xmlns:stream=‘http://etherx.jabber.org/streams’ id=‘16282940281844612208’ from=‘atalk.org’ version=‘1.0’ xml:lang=‘en’>stream:featuresSCRAM-SHA-1PLAINX-OAUTH2</stream:fea tures>

01-13 15:00:42.087 org.atalk.android D/SMACK: SENT (0):

01-13 15:00:42.107 org.atalk.android D/SMACK: RECV (0):

01-13 15:00:42.137 org.atalk.android D/SMACK: SENT (0): <stream:stream xmlns=‘jabber:client’ to=‘atalk.org’ xmlns:stream=‘http://etherx.jabber.org/streams’ version=‘1.0’ xml:lang=‘en’>

01-13 15:00:42.147 org.atalk.android D/SMACK: RECV (0): <?xml version='1.0'?><stream:stream xmlns=‘jabber:client’ xmlns:stream=‘http://etherx.jabber.org/streams’ id=‘18227248040208343624’ from=‘atalk.org’ version=‘1.0’ xml:lang=‘en’>

01-13 15:00:42.147 org.atalk.android D/SMACK: RECV (0): stream:featuresSCRAM-SHA-1PLAINX-OAUTH2</stream:fea tures>

01-13 15:00:42.147 org.atalk.android D/SMACK: XMPPConnection connected (XMPPTCPConnection[leopard@atalk.org/atalk] (0))

01-13 15:00:42.147 org.atalk.android D/SMACK: SENT (0): biwsbj1sZW9wYXJkLHI9eSlaZnoqRUY6XTc4d0FUdGd4QU1DVHQwTWc 6WmJRa1s=

01-13 15:00:42.207 org.atalk.android D/SMACK: RECV (0): cj15KVpmeipFRjpdNzh3QVR0Z3hBTUNUdDBNZz paYlFrW0JqdlVldmc3YTExY1JRc0tpeGhXZmc9PSxzPUNxQmkvM2h5a2JWckRFcnd6RlNJTGc9PSxpPT QwOTY=

01-13 15:00:42.207 org.atalk.android D/SMACK: SENT (0): Yz1iaXdzLHI9eSlaZnoqRUY6XTc4d0FUdGd4QU 1DVHQwTWc6WmJRa1tCanZVZXZnN2ExMWNSUXNLaXhoV2ZnPT0scD14U1Bkbjl5bVdqVytyaTJhbTJTRU R5bUlJVk09

01-13 15:00:42.217 org.atalk.android D/SMACK: RECV (0): dj1oRFpvWDlSTTdlaXNOVnAybjNLYlFSV0pxdX M9

01-13 15:00:42.217 org.atalk.android D/SMACK: SENT (0): <stream:stream xmlns=‘jabber:client’ to=‘atalk.org’ xmlns:stream=‘http://etherx.jabber.org/streams’ version=‘1.0’ id=‘18227248040208343624’ xml:lang=‘en’>

01-13 15:00:42.407 org.atalk.android D/SMACK: RECV (0): <?xml version='1.0'?><stream:stream xmlns=‘jabber:client’ xmlns:stream=‘http://etherx.jabber.org/streams’ id=‘12510061377263721146’ from=‘atalk.org’ version=‘1.0’ xml:lang=‘en’>

01-13 15:00:42.407 org.atalk.android D/SMACK: RECV (0): stream:features</stream:features>

01-13 15:00:42.407 org.atalk.android D/SMACK: RECV (0):

01-13 15:00:42.407 org.atalk.android D/SMACK: User logged (0): leopard@atalk.org:5222/atalk

01-13 15:00:42.407 org.atalk.android D/SMACK: XMPPConnection authenticated (XMPPTCPConnection[leopard@atalk.org/atalk] (0)) and resumed

01-13 15:00:42.407 org.atalk.android D/SMACK: RECV (0):

01-13 15:00:42.407 org.atalk.android D/SMACK: SENT (0): ed341d7cb4d39f423989c0cf5fe8d9527be3ffde

01-13 15:00:42.417 org.atalk.android W/αTalk: [7] org.jivesoftware.smack.roster.Roster.processStanza() Roster not loaded while processing Presence Stanza [from=abc123@atalk.org/jitsi-1f93jo1,id=uth8t-75,type=unavailable,]

01-13 15:00:42.747 org.atalk.android D/SMACK: RECV (0):

01-13 15:00:42.747 org.atalk.android D/SMACK: RECV (0):

01-13 15:01:48.387 org.atalk.android I/αTalk: [1] org.atalk.android.aTalkApp.setCurrentActivity().326 Current activity set to null

01-13 15:01:48.977 org.atalk.android V/ActivityThread: updateVisibility : ActivityRecord{c48ca94 token=android.os.BinderProxy@30b22dc5 {org.atalk.android/org.atalk.android.gui.aTalk}} show : false

01-13 15:03:38.567 org.atalk.android W/art: Suspending all threads took: 7.981ms

01-13 15:04:42.657 org.atalk.android D/SMACK: RECV (0):

01-13 15:04:42.657 org.atalk.android D/SMACK: RECV (0):

01-13 15:04:42.657 org.atalk.android D/SMACK: SENT (0):

01-13 15:04:42.697 org.atalk.android D/SMACK: SENT (0):

I found the problem. It is not Smack library issue but aTalk own problem.

When aTalk received connectionClosedOnError(Exception exception), it performs disconnectAndCleanConnection().

This methods executed three undesired steps which led to the observed problem.

mConnection.removeConnectionListener(connectionListener);
connectionListener = null;

mConnection = null;

While using aTalk own ReconnectionPlugin, it goes through aTalk own sign in process, hence there is no problem.

However when aTalk moves to use smack ReconnectionManager, the above steps must not be executed.

Sorry for the inconvenience caused.

======================

In ReconnectionManager#run line 234 statement can be removed.

for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectingIn(0);
}

as the above has been taken care in the while loop just before the above statement

remainingSeconds–;

for (ConnectionListener listener : connection.connectionListeners) {

listener.reconnectingIn(remainingSeconds);

}