From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=1.0 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,TVD_RCVD_IP shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: [PATCH] close_connection_after_writing only if not deferred, as in cool.io Date: Tue, 18 Dec 2012 21:45:38 +0000 Message-ID: <20121218214538.GA12275@dcvr.yhbt.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1355867144 9731 80.91.229.3 (18 Dec 2012 21:45:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Dec 2012 21:45:44 +0000 (UTC) To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Tue Dec 18 22:45:58 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:423 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tl4z8-0004M6-7L for gclrrg-rainbows-talk@m.gmane.org; Tue, 18 Dec 2012 22:45:58 +0100 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id BE7712E07B; Tue, 18 Dec 2012 21:45:45 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 7818B2E075 for ; Tue, 18 Dec 2012 21:45:41 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0ABB81F42E; Tue, 18 Dec 2012 21:45:39 +0000 (UTC) "Lin Jen-Shin (godfat)" wrote: > I don't have 100% confidence about this, > but running test suite "t/t0002-graceful.sh" > during my development for EventMachineThreadPool Heh, I gave that a shot way back in the day but never got it working to my satisfaction. Perhaps your fix is what is needed... > would need this to properly pass the tests. > > I think this would be needed while using > `throw :async' as well? I don't think so, you just need to set @deferred=nil in a few places before calling quit. I've updated the patch and commit message. Will apply unless you have objections: --------------------------------8<---------------------------------- >>From 42bf1f6de55b82af46fd8255453036c6582b7f19 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 19 Dec 2012 04:03:55 +0800 Subject: [PATCH] event_machine: avoid close on deferred response close_connection_after_writing only if not deferred, as in cool.io Deferred responses may buffer more data down the line, so keep the connection alive if we have a deferred response body. [ew: clear @deferred when we really want to quit, updated commit message] Acked-by: Eric Wong --- lib/rainbows/event_machine/client.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rainbows/event_machine/client.rb b/lib/rainbows/event_machine/client.rb index fc0dfe3..f3c2070 100644 --- a/lib/rainbows/event_machine/client.rb +++ b/lib/rainbows/event_machine/client.rb @@ -28,7 +28,7 @@ class Rainbows::EventMachine::Client < EM::Connection def quit super - close_connection_after_writing + close_connection_after_writing if nil == @deferred end def app_call input @@ -48,6 +48,7 @@ class Rainbows::EventMachine::Client < EM::Connection def deferred_errback(orig_body) @deferred.errback do orig_body.close if orig_body.respond_to?(:close) + @deferred = nil quit end end @@ -103,7 +104,8 @@ class Rainbows::EventMachine::Client < EM::Connection def next! @deferred.close if @deferred.respond_to?(:close) - @hp.keepalive? ? receive_data(@deferred = nil) : quit + @deferred = nil + @hp.keepalive? ? receive_data(nil) : quit end def unbind -- Eric Wong _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying