rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: rack-devel@googlegroups.com
Cc: clogger@librelist.com
Subject: Re: Error when using Mogrel handler and Clogger together
Date: Wed, 9 Sep 2009 10:23:48 -0700	[thread overview]
Message-ID: <20090909172348.GB25506@dcvr.yhbt.net> (raw)
In-Reply-To: <cc1f582e0909090743p5fe8b375va0ddbb33e998cde8@mail.gmail.com>


Iñaki Baz Castillo <ibc@aliax.net> 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: #<NoMethodError: undefined
> method `close' for #<Array:0x7fed7c410c28>>
> /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 <normalperson@yhbt.net>
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 "<GET /hello?goodbye=true HTTP/1.0>", 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

      reply	other threads:[~2009-09-09 17:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-09 14:43 Error when using Mogrel handler and Clogger together Iñaki Baz Castillo
2009-09-09 17:23 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090909172348.GB25506@dcvr.yhbt.net \
    --to=rack-devel@googlegroups.com \
    --cc=clogger@librelist.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).