rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* Error when using Mogrel handler and Clogger together
@ 2009-09-09 14:43 Iñaki Baz Castillo
  2009-09-09 17:23 ` Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Iñaki Baz Castillo @ 2009-09-09 14:43 UTC (permalink / raw)
  To: rack-devel, clogger


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'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:83:in
`process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/usr/lib/ruby/gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:38:in `run'



The code is simple:

-------------
rack_app = Rack::Builder.new {
  use Clogger, :logger => ::MyServer::Logger, :format => "HTTP:
$remote_addr \"$request_method $request_uri\" $status $response_length
$request_time{4}".freeze
  use Rack::ContentLength  # Avoid chunked body until new Rack release.
  run rack_inner_app
}.to_app
-------------

-- 
Iñaki Baz Castillo
<ibc@aliax.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Error when using Mogrel handler and Clogger together
  2009-09-09 14:43 Error when using Mogrel handler and Clogger together Iñaki Baz Castillo
@ 2009-09-09 17:23 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2009-09-09 17:23 UTC (permalink / raw)
  To: rack-devel; +Cc: clogger


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-09 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-09 14:43 Error when using Mogrel handler and Clogger together Iñaki Baz Castillo
2009-09-09 17:23 ` Eric Wong

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

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