Wednesday, April 20, 2011

Please confirm that this XMPP code is not threadsafe

I'm reading the source code to the Smack api and the the method XMPPConnection#disconnect looks like this:

public void disconnect(Presence unavailablePresence) {
    // If not connected, ignore this request.
    if (packetReader == null || packetWriter == null) {


    if (roster != null) {
        roster = null;

    wasAuthenticated = false;

    packetWriter = null;
    packetReader = null;

In my scenario, I am storing a live XMPPConnection inside a class called Session. A separate thread of execution will attempt to close my instance of XMPPConnection by calling Session#shutdown(). As I see it, I will have to cooperatively tell Session to close the XMPPConnection by acquiring a mutex or something. Correct?

From stackoverflow
  • Looks like it's a known bug.

    Jacques René Mesrine : Thanks for pointing out the bug. It is inevitable then that I sync externally before calling it. Peace.


Post a Comment