Possible race condition when logging into XMPP Transport


I'm writing a testcase to verify that some Kraken functionality works as I expect it to, using Smack. I have two users with an XMPP transport registered to each of them. I do the following:

1. Connect to each user's account.
2. Have user1 add user2 as a contact.
3. Have user2 respond to user1, authorizing the request (done automatically by Smack).
4. Wait until I receive a status of "available" for the user2 in user1's roster.

I am encountering some strange behaviour - it looks like a race condition between XMPPSession.login(), which calls XMPPSession.syncUsers() in a separate thread, and the addContact() call. ie, the contact is getting added, but the roster returned from the remote XMPP server during the syncUsers() method doesn't yet contain this contact - and so the contact is being removed again (causing my step #3 to block forever).

I have included a zipfile containing the java testcase I am using, as well as two textfiles - one containing the output when I run with a delay, and one containing the output when I run without this initial delay. You will need to copy local.properties.template to local.properties and fill in appropriate values for the parameters in order to run the test (there are comments in the template file that should help with this). You also need smack.jar, smackx.jar on the classspath to run the test.

Please note that, even with the delay, the test does not run to completion... I believe this may be due to another issue in Kraken... it looks like the XMPP transport doesn't handle subscribe requests properly (BaseTransport.java:502). So when the "buddy" user waits for the "test" user, the "test" user never becomes "available" because the "buddy" user is not actually properly subscribed to the "test" user, so doesn't receive presence updates.




John Doe
September 15, 2010, 7:20 PM

Libraries you'll need:

  • smack.jar (I'm using 3.1.0)

  • smackx.jar (for debug UI)

  • junit-4.+.jar

I have no build process for this... I've been running the test through Eclipse.


Daniel Henninger


John Doe



Expected Effort


Ignite Forum URL



Fix versions