powered by Jive Software

Smack cannot reconnect if server goes down


#1

Hi,

I’m developing an IoT project using Raspberry Pi 3 and Smack 4.2.1. I decided to setup my own XMPP chat server and I’ve selected eJabberd for this. Server version I’m currently using is 17.0.1.

I’ve build application which is used to communicate with the server in order to control the device and I’m having issues with reconnecting to the server when server goes down for some reason and then comes back again. Actually, problems occurs when server goes down 2nd time during the same XMPP session (I’m testing some server settings and I manually stop and start eJabberd server).

Basically, in my application I setup connection and ReconnectionManager and then connect and login to the server. All works perfectly. When I stop the server, Smack immediately recognizes disconnection and starts counting timeout to reconnect and repeats reconnection procedure as long as server is down. When I start the server, Smack succeeds to reconnect first time and then everything is ok with the connection. If I stop the server for the 2nd time during same XMPP session, Smack again recognizes disconnection and starts reconnecting procedure, but when I start the server again, this time Smack cannot reconnect successfully to the server. This time I’m getting errors.

At first, when Smack tries to reconnect, I’m getting “connected” event from my connection object and after that I get “reconnectionFailed” event from ReconnectionManager. Then comes longer pause and then I get exception described below:

14:02:09 Reconnection failed due to an exception (XMPPTCPConnection[***@***/***] (0))org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). While waiting for successful SASL authentication
	at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:93)
	at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:224)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginInternal(XMPPTCPConnection.java:386)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:493)
	at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:450)
	at org.jivesoftware.smack.ReconnectionManager$2.run(ReconnectionManager.java:254)
	at java.lang.Thread.run(Thread.java:745)

And then as final I get “connectionClosedOnError” event from connection object with these 2 exceptions:

okt 25, 2017 2:02:54 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection XMPPTCPConnection[***@***/***] (0) closed with error
java.lang.NullPointerException
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1194)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:982)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:998)
	at java.lang.Thread.run(Thread.java:745)

14:02:54 XMPPConnection closed due to an exception (XMPPTCPConnection[***@***/***] (0))java.lang.NullPointerException
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1194)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:982)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:998)
	at java.lang.Thread.run(Thread.java:745)

From this moment, my connection object always says it is connected and I cannot login to the server at all. As a workaround I can catch this NoResponseException and then create new connection object and connect to the server with it.

Is this a Smack bug or did I forget to setup something with my connection?

Thanks in advance


#2

Thanks for your issue report.

I first thought that XMPPTCPConnection's parser field is null for some reason, but I find it more likely that parser.getName() returns null here. An XMPP trace would be extremely helpful to get an idea about what exactly is going on. Please have a look at https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help,-report-an-issue-and-possible-solve-the-problem-yourself


#3

Has there been any traction on this? I am seeing the same behavior when my XMPP server (OpenFire) goes down (we have it scheduled to go down every night):

2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT java.io.EOFException: input contained no data
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3003) ~[xpp3-1.1.4c.jar!/:na]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) ~[xpp3-1.1.4c.jar!/:na]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410) ~[xpp3-1.1.4c.jar!/:na]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395) ~[xpp3-1.1.4c.jar!/:na]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) ~[xpp3-1.1.4c.jar!/:na]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1248) [smack-tcp-4.2.4.jar!/:4.2.4]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:1000) [smack-tcp-4.2.4.jar!/:4.2.4]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1016) [smack-tcp-4.2.4.jar!/:4.2.4]
2018-08-16T00:44:47.08-0400 [APP/PROC/WEB/1] OUT at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]