shutdown client socket for apps which fork in background
authorEric Wong <normalperson@yhbt.net>
Thu, 12 Apr 2012 23:46:24 +0000 (16:46 -0700)
committerEric Wong <normalperson@yhbt.net>
Fri, 13 Apr 2012 01:50:39 +0000 (18:50 -0700)
commitb26d3e2c4387707ca958cd9c63c213fc7ac558fa
tree00644868cdee0a39aee9b4c7459bd08c9d2ae3c4
parentd258653745e1c8e8fa13b95b1944729294804946
shutdown client socket for apps which fork in background

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
lib/unicorn/http_server.rb
lib/unicorn/ssl_client.rb
t/detach.ru [new file with mode: 0644]
t/t0021-process_detach.sh [new file with mode: 0755]