Re: [hybi] Races in websocket API?

John Fallows <john.fallows@kaazing.com> Fri, 20 November 2009 05:34 UTC

Return-Path: <john.fallows@kaazing.com>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id AB3A33A6A1C for <hybi@core3.amsl.com>; Thu, 19 Nov 2009 21:34:05 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.282
X-Spam-Level:
X-Spam-Status: No, score=-0.282 tagged_above=-999 required=5 tests=[AWL=1.095, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, J_CHICKENPOX_26=0.6]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QLAplX9njhbf for <hybi@core3.amsl.com>; Thu, 19 Nov 2009 21:34:04 -0800 (PST)
Received: from mail-bw0-f223.google.com (mail-bw0-f223.google.com [209.85.218.223]) by core3.amsl.com (Postfix) with ESMTP id 7C69E3A692E for <hybi@ietf.org>; Thu, 19 Nov 2009 21:34:04 -0800 (PST)
Received: by bwz23 with SMTP id 23so3190979bwz.29 for <hybi@ietf.org>; Thu, 19 Nov 2009 21:33:58 -0800 (PST)
MIME-Version: 1.0
Received: by 10.204.10.149 with SMTP id p21mr960457bkp.3.1258695236572; Thu, 19 Nov 2009 21:33:56 -0800 (PST)
In-Reply-To: <4B04C2D6.8010908@webtide.com>
References: <4B04C2D6.8010908@webtide.com>
Date: Thu, 19 Nov 2009 21:33:56 -0800
Message-ID: <c5b3a7130911192133p1c896e0cmcc0713f0a06b4f7c@mail.gmail.com>
From: John Fallows <john.fallows@kaazing.com>
To: Greg Wilkins <gregw@webtide.com>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
Cc: whatwg@lists.whatwg.org, "hybi@ietf.org" <hybi@ietf.org>
Subject: Re: [hybi] Races in websocket API?
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Nov 2009 05:34:05 -0000

Greg,

We raised this as a potential issue during the API design for
WebSocket (back when it was called TCPConnection), indicating that a
separate method might be desirable that could be called after the
WebSocket was constructed and event handlers attached.

But the decision was made that a single-threaded execution environment
made a separate method unnecessary, because the execution of the
onopen handler (for example) could not preempt the execution of the
following 2 lines of JavaScript code:

var ws = new WebSocket("ws://kaazing.net/echo");
ws.onopen = function() { console.log("OPEN"); }

Therefore, by the time the open event is delivered, the onopen handler
would have already been attached.

Kind Regards,
John Fallows.

On Wed, Nov 18, 2009 at 8:00 PM, Greg Wilkins <gregw@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?
>
> 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@ietf.org
> https://www.ietf.org/mailman/listinfo/hybi
>



-- 
>|< Kaazing Corporation >|<
John Fallows | CTO | +1.650.960.8148
888 Villa St, Ste 410 | Mountain View, CA 94041, USA