Wait for running threads on XmppSession.close()

Issue #41 closed
Sven Bartscher created an issue

When calling the .close() method on a XmppSession, while another thread, that uses the XmppSession, is running (e.g. PresenceListeners) the running threads throw IllegalStateExceptions, because the XmppSession was closed.

This is very inconvenient. Especially if your main thread doesn't run long enough for letting the other threads process the batch of presence changes after the login.

I would expect the .close() method to wait for the running threads to terminate and only then close the connection (or optionally take a timeout after which the connection is closed, thus crashing the running threads).

Comments (7)

  1. Sven Bartscher reporter

    I tried to reproduce this accurately. It turns out that I can't reproduce what I observed some weeks ago. I noticed that the "Avatar Request Thread" throws an exception in the attached reproduction program, but that's not what I observed and doesn't seem to cause any harm. I also noticed that the listener threads don't terminate with an exception, but rather seem to be daemon threads and just terminate as soon as the main thread dies. I guess this is a feature rather than a bug.

  2. Christian Schudt repo owner

    Yes, the listener threads are daemon threads (by design). I can't find any "reproduction program", where do you have it?

  3. Christian Schudt repo owner

    Thanks, I could reproduce the issue. Coincidentally I was just about to release 0.5.1 and I've fixed this bug as well. So you could try it out. Maybe the fix is not the best solution, but good enough for the 0.5 branch.

  4. Christian Schudt repo owner

    Dispose Managers when closing the session has started, not after it's closed.

    This allows them to properly close before the session is closed, e.g. sending stanzas. Also allow stanzas to be sent while the session is in closing status.

    Fixes issue #41.

    → <<cset f34be24b0009>>

  5. Log in to comment