From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs357359fgw; Wed, 9 Sep 2009 10:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.142.1.9 as permitted sender) client-ip=10.142.1.9; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.142.1.9 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.142.1.9]) by 10.142.1.9 with SMTP id 9mr307482wfa.22.1252517045641 (num_hops = 1); Wed, 09 Sep 2009 10:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:date:from:to:cc :subject:message-id:references:mime-version:content-type :content-disposition:content-transfer-encoding:in-reply-to :user-agent:reply-to:sender:precedence:x-google-loop:mailing-list :list-id:list-post:list-help:list-unsubscribe:x-beenthere-env :x-beenthere; bh=Vb48TxFRa/NWJUop5hVstnmuQkUKY2aA5i9QIT/qHck=; b=w1T+yZ/EI+7nSPpHgFID9CoC8jQsZvZcFY8PhQlDK6689QEtOkFrLsUCmJRdLR2ytS ZjqEOtNWlCTqqCXVc3n+mlhyerYXEciMYUNcF2/BEsXVOoKX/jjXFI8p6fCoZgya3MHE NbxwYEMZWsQgxzMNQHYLyFjoC3omxTnNk7hp4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:date :from:to:cc:subject:message-id:references:mime-version:content-type :content-disposition:content-transfer-encoding:in-reply-to :user-agent:reply-to:sender:precedence:x-google-loop:mailing-list :list-id:list-post:list-help:list-unsubscribe:x-beenthere-env :x-beenthere; b=S0xceFDP2VgkGjMvMyQaGScsKUmjBG42OnpHwedgUUhh/DUcabogr+2Nq5L9gafheh OtJNcYDE2+CGPgQj4SpDg2hSh5OT/4wfsTjEsPCVk4mF+cO2cQTiFVEQyzr6GOkdFAOK Xqmsb2tt8SFysdkeeQc3iFqldDQfHy1zTglqM= Received: by 10.142.1.9 with SMTP id 9mr37075wfa.22.1252517045574; Wed, 09 Sep 2009 10:24:05 -0700 (PDT) Received: by 10.107.167.28 with SMTP id u28gr1651pro.0; Wed, 09 Sep 2009 10:23:54 -0700 (PDT) X-Sender: normalperson@yhbt.net X-Apparently-To: rack-devel@googlegroups.com Received: by 10.115.26.19 with SMTP id d19mr217916waj.4.1252517032624; Wed, 09 Sep 2009 10:23:52 -0700 (PDT) Received: by 10.115.26.19 with SMTP id d19mr217915waj.4.1252517032586; Wed, 09 Sep 2009 10:23:52 -0700 (PDT) Return-Path: Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by gmr-mx.google.com with ESMTP id 19si522957pzk.4.2009.09.09.10.23.52; Wed, 09 Sep 2009 10:23:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) smtp.mail=normalperson@yhbt.net Received: from localhost (user-118bg0q.cable.mindspring.com [66.133.192.26]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id 72F371F447; Wed, 9 Sep 2009 17:23:49 +0000 (UTC) Date: Wed, 9 Sep 2009 10:23:48 -0700 From: Eric Wong To: rack-devel@googlegroups.com Cc: clogger@librelist.com Subject: Re: Error when using Mogrel handler and Clogger together Message-ID: <20090909172348.GB25506@dcvr.yhbt.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com Iņaki Baz Castillo wrote: > > Hi, when I use Rack Mongrel handler and Clogger and error occurs when > a request arrives: > > > D 2009-09-09 16:29:09 [21978] DEBUG : HTTP: 91.121.79.216 "GET > /xxxxxx" 200 831 0.0036 > > Wed Sep 09 16:29:09 +0200 2009: Read error: # method `close' for #> > /usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:83:in `close' Hi Iņaki, You found a bug in Clogger, I've just released 0.0.7 which should fix it. Patch is below, thanks for the report! >From 7eb0c4e29e567f02affc202b51eb277cbae43688 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 9 Sep 2009 10:02:49 -0700 Subject: [PATCH] handle bodies that do not respond to :close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the wrapped Clogger object always responds to close, we cannot blindly delegate the close method to the body without ensuring it can be closed. So ensure that it can be closed before attempting to close it, all return values and errors are trapped and returned. Reported-by: Iņaki Baz Castillo --- ext/clogger_ext/clogger.c | 4 +++- lib/clogger/pure.rb | 2 +- test/test_clogger.rb | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 63322f9..7813c8c 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -656,7 +656,9 @@ static VALUE clogger_close(VALUE self) { struct clogger *c = clogger_get(self); - return rb_funcall(c->body, close_id, 0); + if (rb_respond_to(c->body, close_id)) + return rb_funcall(c->body, close_id, 0); + return Qnil; } /* :nodoc: */ diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb index 2800802..da2c1de 100644 --- a/lib/clogger/pure.rb +++ b/lib/clogger/pure.rb @@ -47,7 +47,7 @@ class Clogger end def close - @body.close + @body.close if @body.respond_to?(:close) end def reentrant? diff --git a/test/test_clogger.rb b/test/test_clogger.rb index e65311f..23d6e58 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -469,4 +469,24 @@ class TestClogger < Test::Unit::TestCase assert_equal "", s end + def test_clogger_body_not_closeable + s = '' + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => s) + status, headers, body = cl.call(@req) + assert_nil body.close + end + + def test_clogger_body_close_return_value + s = '' + body = [] + def body.close + :foo + end + app = lambda { |env| [302, [ %w(a) ], body ] } + cl = Clogger.new(app, :logger => s) + status, headers, body = cl.call(@req) + assert_equal :foo, body.close + end + end -- Eric Wong