[hybi] Races in websocket API?

Greg Wilkins <gregw@webtide.com> Thu, 19 November 2009 04:00 UTC

Return-Path: <gregw@webtide.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 DDC963A67FC for <hybi@core3.amsl.com>; Wed, 18 Nov 2009 20:00:42 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.599
X-Spam-Level:
X-Spam-Status: No, score=-2.599 tagged_above=-999 required=5 tests=[BAYES_00=-2.599]
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 FtDbnLCjKkdL for <hybi@core3.amsl.com>; Wed, 18 Nov 2009 20:00:41 -0800 (PST)
Received: from mail-gx0-f228.google.com (mail-gx0-f228.google.com [209.85.217.228]) by core3.amsl.com (Postfix) with ESMTP id 633F03A68B5 for <hybi@ietf.org>; Wed, 18 Nov 2009 20:00:41 -0800 (PST)
Received: by gxk28 with SMTP id 28so1721251gxk.9 for <hybi@ietf.org>; Wed, 18 Nov 2009 20:00:35 -0800 (PST)
Received: by 10.150.250.33 with SMTP id x33mr693805ybh.31.1258603234738; Wed, 18 Nov 2009 20:00:34 -0800 (PST)
Received: from ?10.10.1.9? (60-242-119-126.tpgi.com.au [60.242.119.126]) by mx.google.com with ESMTPS id 15sm98430gxk.12.2009.11.18.20.00.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 18 Nov 2009 20:00:33 -0800 (PST)
Message-ID: <4B04C2D6.8010908@webtide.com>
Date: Thu, 19 Nov 2009 15:00:22 +1100
From: Greg Wilkins <gregw@webtide.com>
User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
MIME-Version: 1.0
To: whatwg@lists.whatwg.org
X-Enigmail-Version: 0.95.7
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
Cc: "hybi@ietf.org" <hybi@ietf.org>
Subject: [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: Thu, 19 Nov 2009 04:00:43 -0000

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