about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-04-12 16:46:24 -0700
committerEric Wong <normalperson@yhbt.net>2012-04-12 18:50:39 -0700
commitb26d3e2c4387707ca958cd9c63c213fc7ac558fa (patch)
tree00644868cdee0a39aee9b4c7459bd08c9d2ae3c4 /lib
parentd258653745e1c8e8fa13b95b1944729294804946 (diff)
downloadunicorn-b26d3e2c4387707ca958cd9c63c213fc7ac558fa.tar.gz
Previously we relied on implicit socket shutdown() from the
close() syscall.  However, some Rack applications fork()
(without calling exec()), creating a potentially long-lived
reference to the underlying socket in a child process.  This
ends up causing nginx to wait on the socket shutdown when the
child process exits.

Calling shutdown() explicitly signals nginx (or whatever client)
that the unicorn worker is done with the socket, regardless of
the number of FD references to the underlying socket in
existence.

This was not an issue for applications which exec() since
FD_CLOEXEC is always set on the client socket.

Thanks to Patrick Wenger for discovering this.  Thanks to
Hongli Lai for the tip on using shutdown() as is done in
Passenger.

ref: http://mid.gmane.org/CAOG6bOTseAPbjU5LYchODqjdF3-Ez4+M8jo-D_D2Wq0jkdc4Rw@mail.gmail.com
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/http_server.rb1
-rw-r--r--lib/unicorn/ssl_client.rb5
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index ede6264..f942e2f 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -536,6 +536,7 @@ class Unicorn::HttpServer
     end
     @request.headers? or headers = nil
     http_response_write(client, status, headers, body)
+    client.shutdown # in case of fork() in Rack app
     client.close # flush and uncork socket immediately, no keepalive
   rescue => e
     handle_error(client, e)
diff --git a/lib/unicorn/ssl_client.rb b/lib/unicorn/ssl_client.rb
index 7b41cd2..a8c79e3 100644
--- a/lib/unicorn/ssl_client.rb
+++ b/lib/unicorn/ssl_client.rb
@@ -3,4 +3,9 @@
 class Unicorn::SSLClient < Kgio::SSL
   alias write kgio_write
   alias close kgio_close
+
+  # this is no-op for now, to be fixed in kgio-monkey if people care
+  # about SSL support...
+  def shutdown(how = nil)
+  end
 end