Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle exit, reload, and restart immediately if not processing a requ…

…est. References #11471 [guillaume, Jeremy Kemper]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9151 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit c3ce27fbaf839ff203e6c6cef472b0b571ea24ff 1 parent 458fd10
@jeremy jeremy authored
Showing with 32 additions and 16 deletions.
  1. +32 −16 railties/lib/fcgi_handler.rb
View
48 railties/lib/fcgi_handler.rb
@@ -73,18 +73,20 @@ def process!(provider = FCGI)
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 @@ def process_each_request(provider)
end
def process_request(cgi)
- @when_ready = nil
+ @processing, @when_ready = true, nil
gc_countdown
with_signal_handler 'USR1' do
@@ -105,6 +107,8 @@ def process_request(cgi)
dispatcher_error error, 'unhandled dispatch error'
end
end
+ ensure
+ @processing = false
end
def logger
@@ -158,17 +162,29 @@ def exit_now_handler(signal)
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!
Please sign in to comment.
Something went wrong with that request. Please try again.