[hybi] Buffering and error handling (Was: Serf support for BWTP)

Ian Hickson <ian@hixie.ch> Tue, 02 February 2010 01:03 UTC

Return-Path: <ian@hixie.ch>
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 1E3EA3A6767 for <hybi@core3.amsl.com>; Mon, 1 Feb 2010 17:03:41 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.405
X-Spam-Level:
X-Spam-Status: No, score=-2.405 tagged_above=-999 required=5 tests=[AWL=0.194, 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 rQn9c0avEKFN for <hybi@core3.amsl.com>; Mon, 1 Feb 2010 17:03:39 -0800 (PST)
Received: from looneymail-a4.g.dreamhost.com (caibbdcaaaaf.dreamhost.com [208.113.200.5]) by core3.amsl.com (Postfix) with ESMTP id DED2D3A67F2 for <hybi@ietf.org>; Mon, 1 Feb 2010 17:03:16 -0800 (PST)
Received: from ps20323.dreamhostps.com (ps20323.dreamhost.com [69.163.222.251]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by looneymail-a4.g.dreamhost.com (Postfix) with ESMTP id 429AC83BF; Mon, 1 Feb 2010 17:03:53 -0800 (PST)
Date: Tue, 02 Feb 2010 01:03:52 +0000
From: Ian Hickson <ian@hixie.ch>
To: Greg Wilkins <gregw@webtide.com>
In-Reply-To: <4B65FF91.1070702@webtide.com>
Message-ID: <Pine.LNX.4.64.1002020039110.3846@ps20323.dreamhostps.com>
References: <5c902b9e0912180032o33d58da5hf3411baeb1fc5f7f@mail.gmail.com> <Pine.LNX.4.64.1001310829370.3846@ps20323.dreamhostps.com> <4B65FF91.1070702@webtide.com>
Content-Language: en-GB-hixie
Content-Style-Type: text/css
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset="US-ASCII"
Cc: hybi@ietf.org
Subject: [hybi] Buffering and error handling (Was: Serf support for BWTP)
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: Tue, 02 Feb 2010 01:03:41 -0000

On Mon, 1 Feb 2010, Greg Wilkins wrote:
> 
> I believe that the algorithmic specifications that remain in the 
> document actually introduce a significant lack of clarity and ambiguity.
> 
> The algorithms if implemented as described, would have measurable 
> external artefacts.
> 
> For example, when section 4.1 - 5 says "send the following bytes to the 
> remote server 47 45 54 20", do I actually have to send them?  Or can I 
> buffer them with the following bytes.

I've clarified the spec to say that a node can delay arbitrarily long 
(e.g. for buffering) whenever a byte is to be sent.


> Would a server be justified in rejecting the handshake (on security 
> grounds?) because those bytes are not sent in their own TCP/IP packet?

A server can reject the handshake based on the phase of the moon, the time 
of day, the size of packets, anything. No justification is needed.


> The specification relies on assumed common practise and understanding 
> that "send" can actually mean "buffer and flush sometime later, perhaps 
> aggregated with previous and/or following sends".  Relying on assumed 
> interpretation is not a good thing for a spec.

Agreed. That's a good point. I have updated hte spec accordingly.


> Another issue is that only the client-side sentinel framing algorithm 
> says:
>               "If the client
>               runs out of resources for buffering the incoming data, or
>               hits an artificial resource limit intended to avoid
>               resource starvation, then it must fail the Web Socket
>               connection and abort these steps."
> 
> Does this mean that the serverside or client length framing cannot
> reject a connection based on resource limits?  Must this sentence be
> put into every step of the algorithm that says "read a byte"?
>
> Surely it would be better just to express this error handling 
> non-algorithmicaly?

Good point. In fact there is already a paragraph to that effect under that 
algorithm. I've removed the above text.


> In which case your point about "sanely define all the error handling 
> rules" does not stand up well to this example.

By "error handling" I mean logic, not arbitrary limits. e.g. how to parse 
data using an unknown frame type, or how to handle unknown headers, etc.


> There are numerous error handling cases not handled in your algorithms:
> 
>  + int or long  overflow if a very very large number is sent as a
>    frame length.
>  + what to do if a client sends for the length 0x80, 0x80, 0x80, ....
>    do we read and multiply forever or can we conclude that somebody
>    is messing with us?

These is handled by the aforementioned paragraph after the algorithm.


> In the client framing, we are allowed to abort "If no byte could be read 
> because the Web Socket connection is closed".  But the server is not 
> granted that permission.  What can we do if a read times out but the 
> websocket is not closed?

The server is granted blanket permission to close whenever it wants. 
("Servers may close the Web Socket connection whenever desired.", in the 
section titled "Closing the connection".)


> In fact I can see no sanely defined error handling in these algorithms 
> at all.  Can you point me to one example in section 4.2 or 5.3 that is 
> both complete, un-reliant on common sense interpretation and could not 
> be better and less verbosely defined in imperative style?

Step 2 of the "Data framing" algorithm for clients handles all frame 
types, including all 254 errorneous types.

I've designed the framing so as to minimise the number of possible 
errors, so it's true that there aren't many cases of error handling. The 
point is that behaviour is defined for all possible byte streams.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'