Eric Wong <[email protected]> wrote: > Eric Wong <[email protected]> wrote: > > If you SIGQUIT/SIGTERM before the app is loaded, the signal could > > be ignored. This behavior should probably change... > > I pushed the following to git://bogomips.org/unicorn > > From 406b8b0e2ed6e5be34d8ec3cd4b16048233c2856 Mon Sep 17 00:00:00 2001 > From: Eric Wong <[email protected]> > Date: Tue, 2 Aug 2011 23:52:14 +0000 > Subject: [PATCH] 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.
The following completely eliminates the race condition: >From 8de6ab371c1623669b86a5dfa8703c8fd539011f Mon Sep 17 00:00:00 2001 From: Eric Wong <[email protected]> Date: Fri, 19 Aug 2011 22:13:04 +0000 Subject: [PATCH] close race if an exit signal hits the worker before trap The signal handler from the master is still active and will push the pending signal to SIG_QUEUE if a worker receives a signal immediately after forking. --- lib/unicorn/http_server.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index aa8212e..4f516c9 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -549,6 +549,7 @@ class Unicorn::HttpServer def init_worker_process(worker) # we'll re-trap :QUIT later for graceful shutdown iff we accept clients EXIT_SIGS.each { |sig| trap(sig) { exit!(0) } } + exit!(0) if (SIG_QUEUE & EXIT_SIGS)[0] WORKER_QUEUE_SIGS.each { |sig| trap(sig, nil) } trap(:CHLD, 'DEFAULT') SIG_QUEUE.clear -- Eric Wong _______________________________________________ Unicorn mailing list - [email protected] http://rubyforge.org/mailman/listinfo/mongrel-unicorn Do not quote signatures (like this one) or top post when replying
