summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-08-02 23:52:14 (GMT)
committer Eric Wong <normalperson@yhbt.net>2011-08-02 23:52:14 (GMT)
commit406b8b0e2ed6e5be34d8ec3cd4b16048233c2856 (patch)
tree809b7ee89cc4ee53cd94093962c3ef7a40fe37ae
parent6d56d7ab891d2cb6127b4cba428a0f7c13b9d2ce (diff)
downloadunicorn-406b8b0e2ed6e5be34d8ec3cd4b16048233c2856.tar.gz
trap death signals in the worker sooner
This helps close a race condition preventing shutdown if loading the application (preload_app=false) takes a long time and the user decides to kil workers instead.
-rw-r--r--lib/unicorn/http_server.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index ad5d6f0..565f132 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -535,12 +535,17 @@ class Unicorn::HttpServer
handle_error(client, e)
end
+ EXIT_SIGS = [ :QUIT, :TERM, :INT ]
+ WORKER_QUEUE_SIGS = QUEUE_SIGS - EXIT_SIGS
+
# gets rid of stuff the worker has no business keeping track of
# to free some resources and drops all sig handlers.
# traps for USR1, USR2, and HUP may be set in the after_fork Proc
# by the user.
def init_worker_process(worker)
- QUEUE_SIGS.each { |sig| trap(sig, nil) }
+ # we'll re-trap :QUIT later for graceful shutdown iff we accept clients
+ EXIT_SIGS.each { |sig| trap(sig) { exit!(0) } }
+ WORKER_QUEUE_SIGS.each { |sig| trap(sig, nil) }
trap(:CHLD, 'DEFAULT')
SIG_QUEUE.clear
proc_name "worker[#{worker.nr}]"
@@ -578,7 +583,6 @@ class Unicorn::HttpServer
# closing anything we IO.select on will raise EBADF
trap(:USR1) { nr = -65536; SELF_PIPE[0].close rescue nil }
trap(:QUIT) { worker = nil; LISTENERS.each { |s| s.close rescue nil }.clear }
- [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
logger.info "worker=#{worker.nr} ready"
begin