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) {
        return;
    }

    shutdown(unavailablePresence);

    if (roster != null) {
        roster.cleanup();
        roster = null;
    }

    wasAuthenticated = false;

    packetWriter.cleanup();
    packetWriter = null;
    packetReader.cleanup();
    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.

0 comments:

Post a Comment