Menu

#10 PushletClient.joinListen returns before session ID is saved

open
nobody
None
5
2009-06-05
2009-06-05
Craig M
No

Since the handling of E_JOIN_LISTEN_ACK is processed in a different thread than the one that starts the DataEventListener, it is possible that a call to PushletClient.joinListen will return before the E_JOIN_LISTEN_ACK branch executes to save the session ID. This can cause throwOnInvalidSession if the user calls PushletClient.subscribe immediately after PushletClient.joinListen.

Flow of events that cause the problem:
- Client calls PushletClient.joinListen
- DataEventListener thread is started via startDataEventListener
- DataEventListener sends E_JOIN_LISTEN to pushlet
- DataEventListener notifies thread that started it, joinListen returns
- Client calls PushletClient.subscribe, throwOnInvalidSession is triggered and ID is still null
- Shortly after the E_JOIN_LISTEN_ACK is received and ID is saved

The work around I am using is this:
- Add a boolean field to PushletClient named 'startFromJoinListen'
- Move the 'this.notify()' code in DataEventListener.run() to a method called 'signalReady()'
- If Pushlet.joinListen is called then set startFromJoinListen to true
- In DataEventListener, if (!startFromJoinListen) { signalReady(); } immediately after the call to openURL. However if startFromJoinListen is true then don't call signalReady() until E_JOIN_LISTEN_ACK is received.
This will ensure that there is a session ID saved before further calls can be made. I can submit a patch if you like.

Discussion


Log in to post a comment.