MultiUserChat.leave makes MultiUserChat.join async

The problem: when connection is resumed we want to join MUC again. We call MultiUserChat.join which inside calls leave(). leave() does not wait for result, it’s essentially an async call. Immediately after leave enter(…) is called and it waits for next result. However it gets result of leave and continues. Does not wait for proper MUC join result and this triggers errors if MUC message is sent immediately after join.

The code for join:

public synchronized void join(MucEnterConfiguration mucEnterConfiguration)
    throws XMPPErrorException, NoResponseException, NotConnectedException, InterruptedException, NotAMucServiceException {
    // If we've already joined the room, leave it before joining under a new
    // nickname.
    if (joined) {
        leave();
    }
    enter(mucEnterConfiguration);
}

Proposed solution: make MultiUserChat.leave() a synchronized call. E.g.


public synchronized void leave() throws NotConnectedException, InterruptedException {
...
    connection.sendStanza(leavePresence).nextResultOrThrow(conf.getTimeout());
}
1 Like

Excellent bug report. Thank you very much for your contribution. :slight_smile:

I am surprised that this was not reported earlier.

I’ve created SMACK-848 to track this. Unfortunately the change will require a signature change of the leave() method and thus can’t be included in the next 4.3 release. Hence I had to schedule it for the upcoming 4.4.0 release.

We possibly should still fix the join() behave in 4.3 by introducing a leaveSync() method.

Thank you Flow.

Happy New Year!

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.