Eric Wong normalperson at yhbt.net
Tue Jul 7 16:48:39 EDT 2009

Paul Sponagl <paul at sponagl.de> wrote:
> Hi Eric,
> unicorn does not close the connection on osx after sending the content.
> (It acts as the client would send a Connection: Keep-Alive)
> The connection will be aborted by nginx after about 60
> secs and the content will be send out.
> Macintosh:~> telnet 3001
> Trying
> Connected to localhost.
> Escape character is '^]'.
> GET / HTTP/1.1
> HTTP/1.1 200 OK
> Date: Tue, 07 Jul 2009 08:11:17 GMT
> Status: 200 OK
> Connection: close
> X-Runtime: 293
> ETag: "2659d611050f70fc65c6c052687e5a13"
> Content-Type: text/html; charset=utf-8
> Cache-Control: private, max-age=0, must-revalidate
> Content-Length: 24328
> ...
> the rest of the content

Hi Paul,

This is strange.  Can you tell that you're getting all 24328 bytes of
the content?  And no exception is thrown to stderr, either?  Unicorn
should've closed the socket even on an exception.  Which version of OSX
and Ruby are you running?  Is there anything special/weird about the
Rack response body you're sending?   Does Rack::Lint complain about
anything?  Unicorn is fairly strict about Rack::Lint compatibility.

Does the following patch help?

diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb
index bfaa33d..acf4d04 100644
--- a/lib/unicorn/http_response.rb
+++ b/lib/unicorn/http_response.rb
@@ -60,6 +60,7 @@ module Unicorn
                    "Connection: close\r\n" \
       body.each { |chunk| socket.write(chunk) }
+      socket.flush
       socket.close # flushes and uncorks the socket immediately
         body.respond_to?(:close) and body.close rescue nil

Or you can replace the "socket.close" with "exit!(0)" and really
force it to close :)

Thanks again for trying this!

Eric Wong

More information about the mongrel-unicorn mailing list