[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [hybi] Races in websocket API?



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.>
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


Note Well: Messages sent to this mailing list are the opinions of the senders and do not imply endorsement by the IETF.