users@websocket-spec.java.net

[jsr356-users] [jsr356-experts] Endpoint.onOpen() and Session.addMessageHandler() race condition

From: Joakim Erdfelt <joakim_at_intalio.com>
Date: Wed, 3 Apr 2013 11:16:46 -0700

A scenario for the group to ponder.

   1. You have a ChatEndpoint extends Endpoint class.
   2. WebSocket has been upgraded
   3. Remote starts immediately sending text frames/messages.
   4. Endpoint.onOpen(Session session, EndpointConfig config) is called.
   5. ChatEndpoint.onOpen() performs a session.addMessageHandler(new
   ChatMessageHandler()) call.

If the implementation starts pushing those received messages as it gets
them, then this gap of time between the open and
session.addMessageHandler() can result in lost messages.

Is there a requirement in the spec somewhere that says processing of
received messages should not start until the Endpoint.onOpen (or @OnOpen)
call has completed?
Would seem to make sense.

--
Joakim Erdfelt <joakim_at_intalio.com>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org