Re: [hybi] With deflate-stream, Close frame doesn't work as an end of data marker

Andy Green <andy@warmcat.com> Wed, 09 March 2011 14:30 UTC

Return-Path: <andy.warmcat.com@googlemail.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 4E64F3A69FC for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 06:30:44 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -3.583
X-Spam-Level:
X-Spam-Status: No, score=-3.583 tagged_above=-999 required=5 tests=[AWL=0.016, BAYES_00=-2.599, RCVD_IN_DNSWL_LOW=-1]
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 lFWc-tM0Jxjc for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 06:30:43 -0800 (PST)
Received: from mail-ww0-f44.google.com (mail-ww0-f44.google.com [74.125.82.44]) by core3.amsl.com (Postfix) with ESMTP id E6CAD3A69E4 for <hybi@ietf.org>; Wed, 9 Mar 2011 06:30:42 -0800 (PST)
Received: by wwa36 with SMTP id 36so444615wwa.13 for <hybi@ietf.org>; Wed, 09 Mar 2011 06:31:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:sender:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=8ZLugNJu0yi3OTv53lnkuwMbkIqezFoMCbrej2IVzaY=; b=MiscVLZfwoBIgTAx1+Jp500rmCiYOhORyx4YW5cv9VZOSn1QocVcjHfhCz4dXc+GPE iXjYlJAUjApSyao5Y9aQq98EG9IPEngLQEDG7AF5RzrOFRJOYxUwqAnL5D31Tws06jE6 gsMeG+TTYO6ek0WdiLZRmbVoxyXa/WQQ0Kdf8=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=oBs2pfjK5TwBVSAYB2jWGhSKZFAA1jKixp5uZT9yddEQZbzIpn2bA1no+5/JYYBLQo NNtReynZc03TKyrjPOC8RDrRyy6K7MQKruvcUF0/Ywi5nI0QEm6DYTvFo4fdJEl/l+4l GjAHE500PEDvnFUy5pwku0bSML2KzrFw3JzAA=
Received: by 10.227.165.194 with SMTP id j2mr5826701wby.178.1299681118761; Wed, 09 Mar 2011 06:31:58 -0800 (PST)
Received: from otae.warmcat.com (s15404224.onlinehome-server.info [87.106.134.80]) by mx.google.com with ESMTPS id x1sm1507210wbh.20.2011.03.09.06.31.57 (version=SSLv3 cipher=OTHER); Wed, 09 Mar 2011 06:31:57 -0800 (PST)
Sender: Andy Green <andy.warmcat.com@googlemail.com>
Message-ID: <4D778F5C.3020404@warmcat.com>
Date: Wed, 09 Mar 2011 14:31:56 +0000
From: Andy Green <andy@warmcat.com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110302 Fedora/3.1.8-3.fc16 Thunderbird/3.1.8
MIME-Version: 1.0
To: Takeshi Yoshino <tyoshino@google.com>
References: <OF27A0495D.2C32912B-ON8825784E.00342DCE-8825784E.00367A85@playstation.sony.com> <4D775D69.8010808@warmcat.com> <AANLkTi=4_jp_=QffTsTbrUxjzGTRTv5F4Ao=5ZBpc2FB@mail.gmail.com> <4D777402.3010101@warmcat.com> <AANLkTinJPtZ6Y9oVZt3cMm3rjRMM_EPryS+pNwmcB8hP@mail.gmail.com>
In-Reply-To: <AANLkTinJPtZ6Y9oVZt3cMm3rjRMM_EPryS+pNwmcB8hP@mail.gmail.com>
Content-Type: text/plain; charset="ISO-8859-1"; format="flowed"
Content-Transfer-Encoding: 7bit
Cc: hybi@ietf.org, Yutaka_Takeda@playstation.sony.com
Subject: Re: [hybi] With deflate-stream, Close frame doesn't work as an end of data marker
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: Wed, 09 Mar 2011 14:30:44 -0000

On 03/09/2011 02:02 PM, Somebody in the thread at some point said:

Hi -

> I'm still not sure if we're on the same table. Please allow me to
> explain my thoughts again. Sorry if i'm misunderstanding your point.
>
> Sending a close frame is not a problem. What I'm taking as a (small,

OK.

> but) problem is receiving a close frame. "Trailing bytes after Close
> frame" in Yutaka's post doesn't mean "any further packet" or "any other
> traffic going" on the WebSocket layer. It means trailing bytes generated
> by zlib.
>
> Your code luckily drained the "close, 3 bit header, 00 00 ff ff" which
> contains octets generated by zlib for performing Z_FULL_FLUSH. But
> please imagine someone split them into two TCP packets e.g. "close
> codes, 3 bit header" and "00 00 ff ff" and inserted some delay between

OK.

> them. Your callback is run with eff_buf.token filled with "... close
> codes, 3 bit header", and after that your callback is run again with
> eff_buf.token = "00 00 ff ff".

OK I think I get your idea.  So it is possible at the receiver I get 
enough zlib codes in one packet that it emits the full close frame 
decompressed from inflate(), and I go off and interpret that and try to 
close the socket, but there is already some "dribble" from zlib in 
flight in a second packet which never gets serviced then.

The only thing is I set it to do Z_PARTIAL_FLUSH after every input is 
added to the compressor.  So it means the compressor cannot be holding 
much of anything at the time we come and ask it to send the CLOSE frame 
with Z_FULL_FLUSH.  CLOSE frame is limited to 125 payload.  So it seems 
it would always issue one final compressed output buffer in this case, 
including zlib trailer, which translates to one packet on the wire 
reliably.  I'm also using TCP_NODELAY to stop it aggregating packets and 
causing latency.

I agree it is a theoretical opportunity for something else to fragment 
the packet and make the situation you're describing, but I can't see it 
happening the thing is on a link with like 30-40 byte MTU which is what 
is needed including TCP /IP headers to break the packet there.

Are there other circumstances that can actually cause this I'm 
overlooking too easily?  Thanks for explaining your meaning to me.

-Andy