[whatwg] [hybi] Races in websocket API?

Fumitoshi Ukai (鵜飼文敏) ukai at chromium.org
Wed Nov 18 20:26:04 PST 2009


On Thu, Nov 19, 2009 at 1:00 PM, Greg Wilkins <gregw at webtide.com> wrote:

>
> Is there a race in the websocket API.
>
> When you do:
>
>  var ws = new WebSocket("ws://mysite.com","myprotocol");
>
> then the spec says:
>
>   Return a new WebSocket object, and continue these steps in the
>   background (without blocking scripts).
>
>   Establish a Web Socket connection to a host host, on port port
>   (if one was specified), from origin, with the flag secure, with
>   resource name as the resource name, and with protocol as the
>   protocol (if it is present).
>
>
> So if the next line in the script is
>
>  ws.onopen=myopenfunc;
>
> there is a race between if the onopen function will
> be assigned and if the background connection has been established?
>

I believe open event  is just queued at the moment, and it will be fired
later when javascript becomes idle.

When the Web Socket connection is established, the user agent must run the
following steps:
 Change the readyState attribute's value to OPEN (1).
 Queue a task to fire a simple event named open at the WebSocket object.

-- 
ukai

>
> OK it is currently unlikely that the connect will happen that
> quick - however if I'm running in a rhino test environment
> or a on a browser that is multiplexing the websocket onto an
> already existing connection, then the onopen may indeed be fast.
>
> Similar races exist for onmessage and onclose.  Setting onmessage
> might miss a message that is delivered quickly after the websocket
> is opened.
>
>
> regards
> _______________________________________________
> hybi mailing list
> hybi at ietf.org
> https://www.ietf.org/mailman/listinfo/hybi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20091119/652a0c4e/attachment-0001.htm>


More information about the whatwg mailing list