powered by Jive Software

Smack timeout during disconnect

I’m experiencing problem in my server environment, using the latest Smack version 4.4.x (“smack-java8” library) during shutdown phase, when calling XMPPTCPConnection.disconnect() method.
Disconnect method take 5 seconds (timeout?) to be completed. Enabling Smack debug logs (setting smack.debugEnabled=true) these are sent messages with timestamps:

12:01:57 SENT (0): 
<presence from='backend@xmpp.catapush.rocks/Server1' id='BL621-2' type='unavailable'/>
12:01:57 SENT (0): 
<a xmlns='urn:xmpp:sm:3' h='3'/>
12:01:57 SENT (0): 
12:01:57 RECV (1): 
<presence type="unavailable" xmlns="jabber:client" to="backend@xmpp.catapush.rocks/Server2" from="backend@xmpp.catapush.rocks/Server1"/>
12:02:02 XMPPConnection closed (XMPPTCPConnection[backend@xmpp.catapush.rocks/Server1] (0))
12:02:02 SENT (1): 
<presence from='backend@xmpp.catapush.rocks/Server2' id='DRJ6F-2' type='unavailable'/>
<a xmlns='urn:xmpp:sm:3' h='3'/>
12:02:07 XMPPConnection closed (XMPPTCPConnection[backend@xmpp.catapush.rocks/Server2] (1))

Last log “XMPPConnection closed” comes from my XMPPConnectionListener when connectionClosed event is fired, exactly after 5 seconds from last sent packet.

Here another example, using only one Resource:

15:03:18 SENT (0): 
<presence from='backend@xmpp.catapush.rocks/Server1' id='8TJEI-2' type='unavailable'/>
15:03:18 SENT (0): 
<a xmlns='urn:xmpp:sm:3' h='2'/>
15:03:18 SENT (0): 
15:03:23 XMPPConnection closed (XMPPTCPConnection[backend@xmpp.catapush.rocks/Server1] (0))

Using previous “smack-java7” library version 4.3.5 I don’t find this behaviour, without having 5 seconds timeout, as can be seen from these logs:

14:49:41 SENT (0): <presence from='backend@xmpp.catapush.rocks/Server1' id='8fhPX-21' type='unavailable'></presence>
14:49:41 SENT (0): <a xmlns='urn:xmpp:sm:3' h='3'/>
14:49:41 SENT (0): 
14:49:41 SENT (0): </stream:stream>
14:49:41 RECV (1): <presence type="unavailable" xmlns="jabber:client" to="backend@xmpp.catapush.rocks/Server2" from="backend@xmpp.catapush.rocks/Server1"/>
14:49:41 XMPPConnection closed (XMPPTCPConnection[backend@xmpp.catapush.rocks/Server1] (0))
14:49:41 SENT (1): <presence from='backend@xmpp.catapush.rocks/Server2' id='8fhPX-23' type='unavailable'></presence><a xmlns='urn:xmpp:sm:3' h='3'/>
14:49:41 SENT (1): </stream:stream>
14:49:41 XMPPConnection closed (XMPPTCPConnection[backend@xmpp.catapush.rocks/Server2] (1))

Can someone help us?
Does this behaviour also occur to someone else?

Thank you!

A thread dump taken at the right time would help. That said, my first guess is that Smack waits for the closing stream tag from the server, which is not sent. But then you should see the following log message:

Hi! Thank you for you reply!

I’m trying to log network traffic between smack and my XMPP server, but unfortunately I cannot have clear traffic despite settings


while establishing a connection.

With old Smack version (4.3.x) these 2 configs allow to have clear traffic but with this new version of smack start TLS anyway.
Am I forgetting something?

For what it’s worth, with a very basic client that performs a login and logout, I’m seeing an immediate disconnect. I was using Smack 4.4.2, connecting to Openfire 4.6.4.

<r xmlns='urn:xmpp:sm:3' />
<a xmlns='urn:xmpp:sm:3' h='15' />
21:45:16 RECV (0): 
<iq type="get" id="696-46" to="john@example.org/164vjih9bw" from="example.org">
  <query xmlns="http://jabber.org/protocol/disco#info"/>
<presence id="K12R6-13" from="john@example.org/164vjih9bw" to="john@example.org/164vjih9bw">
  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="https://igniterealtime.org/projects/smack" ver="lWpWNgqtfynY+MxupmhOr2LZqOg=">
<presence id="K12R6-14" type="unavailable" from="john@example.org/164vjih9bw" to="john@example.org/164vjih9bw"/>
21:45:16 XMPPConnection closed (XMPPTCPConnection[john@example.org/164vjih9bw] (0))

Process finished with exit code 0

Client code:

import org.jivesoftware.smack.*;
import org.jivesoftware.smack.tcp.*;

public class TestClient {
    public static void main(String[] args) throws Exception {
        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword("john", "secret")

        AbstractXMPPConnection conn = new XMPPTCPConnection(config);