diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-10-18 22:48:07 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-10-18 22:48:07 -0700 |
commit | e6b2a257cc92d27fe4f404ba5e37ac2887226afc (patch) | |
tree | 7d34583f36f3699d176569cf8d2369ff57a194d8 /lib | |
parent | 580d242fbfe95ea2ce7709f90f25e655bc2d93ac (diff) | |
download | unicorn-e6b2a257cc92d27fe4f404ba5e37ac2887226afc.tar.gz |
Since our :QUIT and :TERM signal handlers are idempotent, we can safely retry sending signals in case workers don't/can't handle them them the first time around. This appears to be a problem with the Thread-based concurrency models in Rainbows! not behaving well (no surprise, though, since pthreads and signals are difficult to manage/mix properly).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn.rb | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 13c203a..681b7d9 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -341,16 +341,13 @@ module Unicorn # Terminates all workers, but does not exit master process def stop(graceful = true) self.listeners = [] - kill_each_worker(graceful ? :QUIT : :TERM) - timeleft = timeout - step = 0.2 - reap_all_workers - until WORKERS.empty? - sleep(step) + limit = Time.now + timeout + until WORKERS.empty? || Time.now > limit + kill_each_worker(graceful ? :QUIT : :TERM) + sleep(0.1) reap_all_workers - (timeleft -= step) > 0 and next - kill_each_worker(:KILL) end + kill_each_worker(:KILL) end private |