summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-26 23:19:09 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-26 23:41:25 +0000
commit7ef05ec23b06f06e9d4bb1cf45d1907b4eeacb80 (patch)
treef89b9055d323781452422d6bba8ba6d8a5a895f7
parent2243c97edf80d635871bc678794f07d6c1d033c2 (diff)
If a moronic sysadmin is sending too many signals, just let them
do it.  It's likely something is terribly wrong when the server
is overloaded with signals, so don't try to protect users from
it.  This will also help in case where TTOU signals are sent too
quickly during shutdown, although sleeping between kill(2)
syscalls is always a good idea because of how non-real-time
signals are delivered.
-rw-r--r--lib/unicorn/http_server.rb25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 513269f..338e8d6 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -50,6 +50,10 @@ class Unicorn::HttpServer
   # signal queue used for self-piping
   SIG_QUEUE = []
 
+  # list of signals we care about and trap in master.
+  QUEUE_SIGS = [ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP, :TTIN, :TTOU ]
+
+  # :startdoc:
   # We populate this at startup so we can figure out how to reexecute
   # and upgrade the currently running instance of Unicorn
   # This Hash is considered a stable interface and changing its contents
@@ -82,7 +86,6 @@ class Unicorn::HttpServer
       }.call,
     0 => $0.dup,
   }
-  # :startdoc:
 
   # Creates a working server on host:port (strange things happen if
   # port isn't a Number).  Use HttpServer::run to start the server and
@@ -151,8 +154,8 @@ class Unicorn::HttpServer
     # setup signal handlers before writing pid file in case people get
     # trigger happy and send signals as soon as the pid file exists.
     # Note that signals don't actually get handled until the #join method
-    QUEUE_SIGS.each { |sig| trap_deferred(sig) }
-    trap(:CHLD) { |_| awaken_master }
+    QUEUE_SIGS.each { |sig| trap(sig) { SIG_QUEUE << sig; awaken_master } }
+    trap(:CHLD) { awaken_master }
     self.pid = config[:pid]
 
     self.master_pid = $$
@@ -354,22 +357,6 @@ class Unicorn::HttpServer
 
   private
 
-  # list of signals we care about and trap in master.
-  QUEUE_SIGS = [ :WINCH, :QUIT, :INT, :TERM, :USR1, :USR2, :HUP,
-                 :TTIN, :TTOU ]
-
-  # defer a signal for later processing in #join (master process)
-  def trap_deferred(signal)
-    trap(signal) do |sig_nr|
-      if SIG_QUEUE.size < 5
-        SIG_QUEUE << signal
-        awaken_master
-      else
-        logger.error "ignoring SIG#{signal}, queue=#{SIG_QUEUE.inspect}"
-      end
-    end
-  end
-
   # wait for a signal hander to wake us up and then consume the pipe
   # Wake up every second anyways to run murder_lazy_workers
   def master_sleep(sec)