powered by Jive Software

Smack connection is treated as alive even the application have been forcibly terminated


After upgrading Smack from 4.0.5 to 4.2.3 I have seen a strange thing. Even if an application have been forcibly terminated, Openfire shows that an user is still online.

The client will probably appear offline for the server as soon as the timeout period is exceeded.

Yes, after while an user goes to offline. But why this behavior exists in 4.2.3 and is absent in 4.0.5?

There is also another issue flows from it. If Openfire treats an user is online and my app starts and tries to enter into existed MUCs, then it fails because it does not receive a stanza from the server.
I repeat my app works fine using Smack 4.0.5.

I believe that it is impossible that this did not exist in 4.0.5. If a client just disappears the server has now way becoming immediately aware of this (because how TCP works). As Paul said, the server will need to run into some sort of timeout after which the connection is declared dead.

You are possibly running into an Openfire issue here. Try a newer version if possibly or a different server.

It is impossibly to tell the exact cause without a detailed problem anlysis which would at least require an XMPP trace.

I believe that it is impossible that this did not exist in 4.0.5.

It is a strange thing but it really is. I don’t have any reason to lie. Smack 4.2.3 has different behavior than 4.0.5.
The application that I develop is commercial. So I can’t provide you any recorded video.
I had to go through not easy process of migration from Smack 4.0.5 to 4.2.3 to fall into these troubles.

Try a newer version if possibly or a different server.

Openfire version is 4.2.3.

It is impossibly to tell the exact cause without a detailed problem anlysis which would at least require an XMPP trace.

I see that a response on a presence stanza is received if user is offline before my app starts. And there is no response on that stanza from the server if it treats that an user is online when my app starts.
Do you really need XMPP log?

Sadly I’ve lost my magic crystal ball which would simply tell me what is going on. :slight_smile: So yes, until you want help you need to provide details. Please also read: https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help,-report-an-issue-and-possible-solve-the-problem-yourself

I also like to point out that I provide professional support.

Log for a case when an user is offline for the server.
normal_start.txt (34.2 KB)

Log for a case when the server thinks that an user is online but in fact it is offline.
failed_start.txt (20.5 KB)


What is your conclusion from the logs?

Please help me to clarify this issue.

Today I intentionally changed my application to work with Smack 4.1.9. And I can to report next results.

Smack 4.1.9:

  • after the application terminated Openfire see the user is offline and left a group chat
  • after the application restarted it successfully rejoins to a group chat

Smack 4.2.0:

  • after the application terminated Openfire see the user is online and joined in a group chat
  • after the application restarted it can not rejoin to a group chat (a timeout occurs)

So as I can see Smack 4.2.x handles connections with Openfire in a different way.

An interesting moment is that Openfire is configured not to disconnect clients that are idle.

P. S. I don’t have permissions to report an issue in Ignite JIRA. Could someone to do this?

I believe we are talking about two situations here: 1. Smack is on a silently broken TCP connection. 2. The TCP connection is not closed on app termination.

Regarding 1) XMPP uses a long lived TCP connection. Sadly the nature of the modern internet and mostly due to broken middleboxes, those connections become broken without the endpoints being notified. If you want to check if your connection is still alive, the only reliable (but still racy) way is to use PingManager.pingMyServer().

Regarding 2) I am not aware of a code change that would cause this behaviorial change. It is not clear what you mean by “application terminated”, but if a Android process is really killed as opposed to just vanishing into the background, the Linux kernel would usually tear down all established TCP connections of the process and thus the XMPP server would become eventually, or at least probably, aware of the terminated XMPP session.

That appears to be an indication that the applications process was not terminated, but that the TCP connection somehow become unusable. This would explain the timeout on join.

What is your application architecture? Which component manages the XMPP connection? An Android Service? How did you terminate the application?

I don’t want to create an issue for 2) until we are really sure it is an issue and have identified a culprit. I did a scan of the relevant commits of that time period, but could find anything (but I could have missed it).

The situation is simple for me. By an unknown reason the library has different behavior depending on version. Smack below 4.2.x works fine in that situation, and Smack 4.2.x and above has a problem. From my side I have brought minimal changes into the code in order the application can work with a specific version of the library.

I don’t understand why you decided that my application works on Android OS. It is a desktop application.

The application in all cases is run under IDE. And the application is terminated means that the application is not alive any more (a process is destroyed completely and not displayed in the task manager).

So you terminate the application without a clean XMPP disconnect. Do you have stream management enabled? I doubt that this is the cause, as Openfire does IIRC not support stream resumption, but give it a try and disable stream management. Please report back your findings.

Yes, in all cases the application is stopped without closing of a XMPP connection.
The stream management is not enabled.

I have found another interesting observation:

  1. start and stop the app with Smack 4.2.3 (Openfire sees an user is online)
  2. start the app with Smack 4.1.9 (rejoin to a group chat fails)
  3. stop the app with Smack 4.1.9 (Openfire sees an user is offline)

As for me Smack 4.1.9 and 4.2.3 free resources in different way.

Flow, have you done research of the issue? Have you found something?

sir i am facing same issue…when i kill app …i send presence unavailable still openfire server shows online…please help if you have solved this issue…