Pages

Wednesday, March 2, 2011

Race Condition with Sametime Proxy Server

I've spent the last few weeks integrating a web based sametime chat client into websphere portal and ran into a curious problem. It seemed that on occasion the buddy list would not populate, all I'd get is a dojo busy indicator, but if I refreshed the page everything would be fine.

Time to open up firebug.

I have to admit that dojo isn't the easiest javascript to debug, they've really stretched the capabilities of the language, but I finally tracked it down to a piece of code during the execution of:

ST_Client = new sametime.WebClient({}, "STClient");

At some point it tests if it should display the buddy list right away or add the task to a queue for later execution, and in this case it was adding to the queue. So who is supposed to deal with the queue, and why wasn't it being done? Turns out that there's some code executed in the login

stproxy.login.loginByPassword()

that iterates through the queue and displays the buddy list. I was running into a race condition because I was trying to log in to the samtime server before showing the buddy list, but in some cases the login was finishing before the call to create the WebClient was done.

The Fix?

Ensure that the code creates the WebClient before it tries to login. Go figure.
Please note that generic comments containing links with the intent of self promotion will be flagged as spam and deleted.

1 comments:

  1. What was I thinking? The nature of a race condition is two or more asynchronous threads that affect each other in an undesirable way. Switching the order of the two statements doesn't really fix anything, it just seemed that way because the timing changes in certain cases.

    The real fix is to ensure that login is complete before trying to create the WebClient(). I just use this instead:

    stproxy.login.loginByToken(null, null, null,loggedInOK, loginFailed);

    // This executes *after* login success
    function loggedInOK() {
    ST_Client = new sametime.WebClient({}, "STClient");
    }

    function loginFailed() {
    alert('Doh');
    }

    ReplyDelete

Are you about to post a generic comment that has nothing to do with this post? Something like "Hey thanks for this very valuable information, BTW here's my website". If so, it will be marked as spam and deleted within 24 hours.

Note: Only a member of this blog may post a comment.