aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/fcgi_handler.rb7
-rw-r--r--railties/test/fcgi_dispatcher_test.rb17
3 files changed, 24 insertions, 2 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index ddb5fcf8ba..25a59b2734 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make fcgi handler respond to TERM signals with an explicit exit [Jamis Buck]
+
* Added demonstration of fixture use to the test case generated by the model generator [DHH]
* If specified, pass PostgreSQL client character encoding to createdb. #2703 [Kazuhiko <kazuhiko@fdiary.net>]
diff --git a/railties/lib/fcgi_handler.rb b/railties/lib/fcgi_handler.rb
index 3d769b71a1..0170d6904e 100644
--- a/railties/lib/fcgi_handler.rb
+++ b/railties/lib/fcgi_handler.rb
@@ -6,7 +6,7 @@ require 'rbconfig'
class RailsFCGIHandler
SIGNALS = {
'HUP' => :reload,
- 'TERM' => :exit,
+ 'TERM' => :exit_now,
'USR1' => :exit,
'USR2' => :restart
}
@@ -117,6 +117,11 @@ class RailsFCGIHandler
dispatcher_log :warn, "Ignoring unsupported signal #{signal}."
end
+ def exit_now_handler(signal)
+ dispatcher_log :info, "asked to terminate immediately"
+ exit
+ end
+
def exit_handler(signal)
dispatcher_log :info, "asked to terminate ASAP"
@when_ready = :exit
diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb
index 2a88e91ea5..cc96c2934c 100644
--- a/railties/test/fcgi_dispatcher_test.rb
+++ b/railties/test/fcgi_dispatcher_test.rb
@@ -30,6 +30,10 @@ class RailsFCGIHandler
def restore!
@reloaded = true
end
+
+ def reload!
+ @reloaded = true
+ end
alias_method :old_run_gc!, :run_gc!
def run_gc!
@@ -62,7 +66,7 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
@handler.send_signal("HUP")
@handler.thread.join
assert_nil @handler.exit_code
- assert_nil @handler.when_ready
+ assert_equal :reload, @handler.when_ready
assert @handler.reloaded
end
@@ -74,6 +78,7 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
@handler.thread.join
assert_nil @handler.exit_code
assert_equal :reload, @handler.when_ready
+ assert @handler.reloaded
end
def test_interrupted_via_USR1_when_not_in_request
@@ -95,6 +100,16 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase
assert_nil @handler.exit_code
assert_equal :exit, @handler.when_ready
end
+
+ def test_interrupted_via_TERM
+ Dispatcher.time_to_sleep = 1
+ @handler.thread = Thread.new { @handler.process! }
+ sleep 0.1 # let the thread get started
+ @handler.send_signal("TERM")
+ @handler.thread.join
+ assert_equal 0, @handler.exit_code
+ assert_nil @handler.when_ready
+ end
%w(RuntimeError SignalException).each do |exception|
define_method("test_#{exception}_in_fcgi") do