about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-11-06 02:24:10 +0000
committerEric Wong <normalperson@yhbt.net>2013-11-06 02:36:27 +0000
commit4c5aefa112a42d293300ba8c1f31230b6163ca76 (patch)
tree9eaad400971c6f068c77d53ccde25ba7d0241caf
parent0151fa2bcba2371a36d22d072ca756f2959de1e0 (diff)
downloadyahns-4c5aefa112a42d293300ba8c1f31230b6163ca76.tar.gz
Double SIGQUIT defeats the use of graceful shutdown.  We must not
watch the worker pipe again for readability after we've initiated
graceful shutdown.
-rw-r--r--lib/yahns/server_mp.rb9
-rw-r--r--lib/yahns/worker.rb7
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 115f94a..d8990ca 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -142,8 +142,9 @@ module Yahns::ServerMP # :nodoc:
   def run_mp_worker(worker)
     fdmap = fdmap_init_mp
     alive = true
+    watch = [ worker, @sev ]
     begin
-      alive = mp_sig_handle(worker, alive)
+      alive = mp_sig_handle(watch, alive)
     rescue => e
       Yahns::Log.exception(@logger, "main worker loop", e)
     end while alive || dropping(fdmap)
@@ -152,10 +153,12 @@ module Yahns::ServerMP # :nodoc:
     quit_finish
   end
 
-  def mp_sig_handle(worker, alive)
+  def mp_sig_handle(watch, alive)
     # not performance critical
-    r = IO.select([worker, @sev], nil, nil, alive ? nil : 0.01) and
+    watch.delete_if { |io| io.to_io.closed? }
+    if r = IO.select(watch, nil, nil, alive ? nil : 0.01)
       r[0].each { |io| io.yahns_step }
+    end
     case @sig_queue.shift
     when *EXIT_SIGS
       return quit_enter(alive)
diff --git a/lib/yahns/worker.rb b/lib/yahns/worker.rb
index 0d25acc..9b1bb8a 100644
--- a/lib/yahns/worker.rb
+++ b/lib/yahns/worker.rb
@@ -23,8 +23,11 @@ class Yahns::Worker # :nodoc:
   # This causes the worker to gracefully exit if the master
   # dies unexpectedly.
   def yahns_step
-    @to_io.kgio_tryread(11) == nil and Process.kill(:QUIT, $$)
-    :wait_readable
+    if @to_io.kgio_tryread(11) == nil
+      Process.kill(:QUIT, $$)
+      @to_io.close
+    end
+    :ignore
   end
 
   # worker objects may be compared to just plain Integers