diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-30 23:07:52 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-03-30 23:07:52 +0000 |
commit | c3ce27fbaf839ff203e6c6cef472b0b571ea24ff (patch) | |
tree | 0fff56d14e16e30f495371bef54204d6ff7ca057 | |
parent | 458fd104838c14be4511c86c5739f8368725ecbd (diff) | |
download | rails-c3ce27fbaf839ff203e6c6cef472b0b571ea24ff.tar.gz rails-c3ce27fbaf839ff203e6c6cef472b0b571ea24ff.tar.bz2 rails-c3ce27fbaf839ff203e6c6cef472b0b571ea24ff.zip |
Handle exit, reload, and restart immediately if not processing a request. References #11471 [guillaume, Jeremy Kemper]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9151 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | railties/lib/fcgi_handler.rb | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb index a644161e7f..722aa1940c 100644 --- a/railties/lib/fcgi_handler.rb +++ b/railties/lib/fcgi_handler.rb @@ -73,18 +73,20 @@ class RailsFCGIHandler def process_each_request(provider) cgi = nil - provider.each_cgi do |cgi| - process_request(cgi) - - case when_ready - when :reload - reload! - when :restart - close_connection(cgi) - restart! - when :exit - close_connection(cgi) - break + catch :exit do + provider.each_cgi do |cgi| + process_request(cgi) + + case when_ready + when :reload + reload! + when :restart + close_connection(cgi) + restart! + when :exit + close_connection(cgi) + throw :exit + end end end rescue SignalException => signal @@ -93,7 +95,7 @@ class RailsFCGIHandler end def process_request(cgi) - @when_ready = nil + @processing, @when_ready = true, nil gc_countdown with_signal_handler 'USR1' do @@ -105,6 +107,8 @@ class RailsFCGIHandler dispatcher_error error, 'unhandled dispatch error' end end + ensure + @processing = false end def logger @@ -158,17 +162,29 @@ class RailsFCGIHandler def exit_handler(signal) dispatcher_log :info, "asked to stop ASAP" - @when_ready = :exit + if @processing + @when_ready = :exit + else + throw :exit + end end def reload_handler(signal) dispatcher_log :info, "asked to reload ASAP" - @when_ready = :reload + if @processing + @when_ready = :reload + else + reload! + end end def restart_handler(signal) dispatcher_log :info, "asked to restart ASAP" - @when_ready = :restart + if @processing + @when_ready = :restart + else + restart! + end end def restart! |