From e6b2a257cc92d27fe4f404ba5e37ac2887226afc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 18 Oct 2009 22:48:07 -0700 Subject: stop continually resends signals during shutdowns 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). --- lib/unicorn.rb | 13 +++++-------- 1 file 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 -- cgit v1.2.3-24-ge0c7