From a764983fccd6cce64043d76e09a5e1718e7f8fd6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Oct 2009 22:42:56 -0700 Subject: refactor graceful shutdowns again, harder We use the "G" global constant from the Rev model everywhere to simplify things a little. Test cases are more consistent now, too. --- lib/rainbows/revactor.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'lib/rainbows/revactor.rb') diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index f61de97..3db1062 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -55,7 +55,7 @@ module Rainbows response = app.call(env) end - alive = hp.keepalive? && ! Actor.current[:quit] + alive = hp.keepalive? && G.alive out = [ alive ? CONN_ALIVE : CONN_CLOSE ] if hp.headers? HttpResponse.write(client, response, out) end while alive and hp.reset.nil? and env.clear @@ -86,7 +86,6 @@ module Rainbows limit = worker_connections revactorize_listeners! clients = {} - alive = true listeners = LISTENERS.map do |s| Actor.spawn(s) do |l| @@ -99,23 +98,16 @@ module Rainbows clients[actor.object_id] = actor root.link(actor) rescue Errno::EAGAIN, Errno::ECONNABORTED - rescue Errno::EBADF - break rescue Object => e - listen_loop_error(e) if alive - end while alive + listen_loop_error(e) + end while G.alive end end m = 0 check_quit = lambda do worker.tmp.chmod(m = 0 == m ? 1 : 0) - if listeners.any? { |l| l.dead? } || - master_pid != Process.ppid || - LISTENERS.first.nil? - alive = false - clients.each_value { |a| a[:quit] = true } - end + G.alive = false if master_pid != Process.ppid end begin @@ -128,7 +120,7 @@ module Rainbows check_quit.call end end - end while alive || clients.size > 0 + end while G.alive || clients.size > 0 end private -- cgit v1.2.3-24-ge0c7