W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2009

[whatwg] [hybi] Races in websocket API?

From: Fumitoshi Ukai <ukai@chromium.org>
Date: Thu, 19 Nov 2009 13:26:04 +0900
Message-ID: <de17d48e0911182026i1a31dcbdoa5edafeb1f48e779@mail.gmail.com>
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.


> 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.htm>
Received on Wednesday, 18 November 2009 20:26:04 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:19 UTC