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

Takeshi Yoshino <tyoshino@google.com> Wed, 09 March 2011 15:48 UTC

Return-Path: <tyoshino@google.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 F37B73A6859 for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 07:48:32 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.738
X-Spam-Level:
X-Spam-Status: No, score=-105.738 tagged_above=-999 required=5 tests=[AWL=0.238, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
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 PS7CwrwpEEwP for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 07:48:31 -0800 (PST)
Received: from smtp-out.google.com (smtp-out.google.com [216.239.44.51]) by core3.amsl.com (Postfix) with ESMTP id 8536D3A6A2E for <hybi@ietf.org>; Wed, 9 Mar 2011 07:48:31 -0800 (PST)
Received: from wpaz17.hot.corp.google.com (wpaz17.hot.corp.google.com [172.24.198.81]) by smtp-out.google.com with ESMTP id p29FnlIC026273 for <hybi@ietf.org>; Wed, 9 Mar 2011 07:49:47 -0800
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1299685787; bh=/4i2Lh+lhAQDftw++NCdVKzk49E=; h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=A7pP9f4/17s4OSUWvlxZZ05T3ZZ2w/K0csTUq2q7/81EaA3yBtN8AEG5xhYU+94u5 V31b1EP0zGPTPfJk34ipQ==
Received: from iym7 (iym7.prod.google.com [10.241.52.7]) by wpaz17.hot.corp.google.com with ESMTP id p29Fn3mf008364 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for <hybi@ietf.org>; Wed, 9 Mar 2011 07:49:46 -0800
Received: by iym7 with SMTP id 7so857909iym.18 for <hybi@ietf.org>; Wed, 09 Mar 2011 07:49:46 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=qwhmXcZ8uwVtj3Ig05hetsBsf6prW0u7t63FG5UQ7wI=; b=AFcXOdzC7RlKABghM+5lLaRVHX72hSlSI2LMhDxwF/fJTQYgq2BJ/aK/wSn4bOtYtm tjaySqe9KD2+5lerymVw==
DomainKey-Signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=T+wij6LNxqAFPR1Zh36GZ5Gd0ADfGsQ1w6/yKoR3SNryVAeSh5tWfYPqLIdEhJb2VK 0xcboN0V5/0XCN+Gwx2g==
Received: by 10.43.61.20 with SMTP id wu20mr8163840icb.371.1299685786135; Wed, 09 Mar 2011 07:49:46 -0800 (PST)
MIME-Version: 1.0
Received: by 10.231.14.141 with HTTP; Wed, 9 Mar 2011 07:49:26 -0800 (PST)
In-Reply-To: <4D778F5C.3020404@warmcat.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> <4D778F5C.3020404@warmcat.com>
From: Takeshi Yoshino <tyoshino@google.com>
Date: Thu, 10 Mar 2011 00:49:26 +0900
Message-ID: <AANLkTik-nQW8o78UM4ynt8U9y=pUMxq1+SA1zkfVy6A4@mail.gmail.com>
To: Andy Green <andy@warmcat.com>
Content-Type: multipart/alternative; boundary="bcaec51a83389a2e6d049e0eada5"
X-System-Of-Record: true
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 15:48:33 -0000

On Wed, Mar 9, 2011 at 23:31, Andy Green <andy@warmcat.com> wrote:

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


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


I'm doing the same in pywebsocket (using Z_SYNC_FLUSH).


> and ask it to send the CLOSE frame with Z_FULL_FLUSH.


Yes, too (Z_SYNC_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.
>
It makes sense.


>
> 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.
>
> Yes. Because of that, I'm not so eager to push this idea... But if we can
have better one, I think it's nice.

One method I can come up with
- by which we can make sure that we recv all the data zlib emit
- that can be applied to stream-based deflate
is putting BFINAL=1 block at the end of stream. zlib does this when Z_FINISH
is specified. That block contains full or some portion of close frame octets
or even empty one after close codes is ok. zlib returns EoF by some manner
when it consumed all the data terminated by BFINAL=1 block.

python's zlib wrapper doesn't have API to probe EoF now, so I can't apply
this to pywebsocket, but it seems it's applicable on many environment
(original C zlib, Java, etc.)


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


>
> -Andy
>