jsr356-experts@websocket-spec.java.net

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

From: Mark Thomas <mark_at_homeinbox.net>
Date: Tue, 09 Apr 2013 22:05:03 -0400

On 03/04/2013 14:16, Joakim Erdfelt wrote:
> 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.

+1

Mark