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

Yutaka_Takeda@PlayStation.Sony.Com Wed, 09 March 2011 21:48 UTC

Return-Path: <Yutaka_Takeda@PlayStation.Sony.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 1C1E93A6AB7 for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 13:48:45 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.059
X-Spam-Level:
X-Spam-Status: No, score=-6.059 tagged_above=-999 required=5 tests=[AWL=0.205, BAYES_00=-2.599, HTML_MESSAGE=0.001, IP_NOT_FRIENDLY=0.334, RCVD_IN_DNSWL_MED=-4]
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 CRssk40Ztdy1 for <hybi@core3.amsl.com>; Wed, 9 Mar 2011 13:48:43 -0800 (PST)
Received: from paris.playstation.sony.com (nat.playstation.sony.com [69.36.131.254]) by core3.amsl.com (Postfix) with ESMTP id 926E03A6AB0 for <hybi@ietf.org>; Wed, 9 Mar 2011 13:48:43 -0800 (PST)
Received: from constantine.playstation.sony.com ([162.49.67.15]) by paris.playstation.sony.com (Lotus Domino Release 8.5.1FP5) with ESMTP id 2011030913495915-252418 ; Wed, 9 Mar 2011 13:49:59 -0800
In-Reply-To: <4D778F5C.3020404@warmcat.com>
To: Andy Green <andy@warmcat.com>
MIME-Version: 1.0
X-KeepSent: 4821AA00:120197B4-8825784E:0076F791; type=4; flags=0; name=$KeepSent
X-Mailer: Lotus Notes Release 7.0.2 September 26, 2006
Message-ID: <OF4821AA00.120197B4-ON8825784E.0076F791-8825784E.00781253@playstation.sony.com>
From: Yutaka_Takeda@PlayStation.Sony.Com
Date: Wed, 09 Mar 2011 13:51:28 -0800
X-MIMETrack: Serialize by Router on SCEA919ML04/SCEA(Release 8.5.1FP3|May 23, 2010) at 03/09/2011 01:49:58 PM, Serialize complete at 03/09/2011 01:49:58 PM, Itemize by SMTP Server on SCEA919ML02/SCEA(Release 8.5.1FP5|September 29, 2010) at 03/09/2011 01:49:59 PM, Serialize by Router on SCEA919ML02/SCEA(Release 8.5.1FP5|September 29, 2010) at 03/09/2011 01:50:01 PM, Serialize complete at 03/09/2011 01:50:01 PM
Content-Type: multipart/alternative; boundary="=_alternative 007812508825784E_="
Cc: hybi@ietf.org
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 21:48:45 -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?

Yes. Since your receive buffer passed in recv(2) has a predetermined 
finite size and you may not be reading all data in the kernel space 
(TCP) buffer. Depending on how it is implemented and timing, the
receiver may successfully extract Close frame out of data you have just
read from TCP socket, and then close the socket without bothering to 
read the outstanding data in the kernel.


- Yutaka


>  Thanks for explaining your meaning to me.
> 
> -Andy
> _______________________________________________
> hybi mailing list
> hybi@ietf.org
> https://www.ietf.org/mailman/listinfo/hybi