about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-08-30 16:18:21 -0700
committerEric Wong <normalperson@yhbt.net>2011-08-30 23:23:21 +0000
commit71b4507755f2bd279adb14e6cdc90e1380efa247 (patch)
treee9ffa38b77c4bcec3619f078d67ea07a01ccc659 /lib/rainbows
parent58a09dccfa425811fa3b66e097c38bb303c2aa1e (diff)
downloadrainbows-71b4507755f2bd279adb14e6cdc90e1380efa247.tar.gz
If any combination of SIGQUIT and SIGUSR1 are sent to a
Rainbows! worker in a /very/ short period of time, the Mutex
used by the default Logger implementation may deadlock since
Mutex synchronization is not reentrant-safe.

Users of alternative logger implementations (or monkey-patched
ones) are possibly not affected.  Users of the logger_mp_safe.rb
monkey-patch distributed[1] with unicorn are not affected.

[1] http://unicorn.bogomips.org/examples/logger_mp_safe.rb
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/base.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index d1c5c08..54f1d2d 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -18,8 +18,11 @@ module Rainbows::Base
     # we're don't use the self-pipe mechanism in the Rainbows! worker
     # since we don't defer reopening logs
     Rainbows::HttpServer::SELF_PIPE.each { |x| x.close }.clear
-    trap(:USR1) { reopen_worker_logs(worker.nr) }
-    trap(:QUIT) { Rainbows.quit! }
+
+    # spawn Threads since Logger takes a mutex by default and
+    # we can't safely lock a mutex in a signal handler
+    trap(:USR1) { Thread.new { reopen_worker_logs(worker.nr) } }
+    trap(:QUIT) { Thread.new { Rainbows.quit! } }
     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
     Rainbows::ProcessClient.const_set(:APP, Rainbows.server.app)
     logger.info "Rainbows! #@use worker_connections=#@worker_connections"