yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
* [REJECT] worker: avoid signaling self for dead parent
@ 2014-05-09  1:05 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2014-05-09  1:05 UTC (permalink / raw)
  To: yahns-public

This avoids generating signals and triggering bugs/sub-optimal
behavior with libraries which do not handle signals well.

I will probably reject this, however since a prematurely dead master
is an exceptional case and not worth the extra ivar storage.
---
 lib/yahns/server_mp.rb | 4 ++--
 lib/yahns/worker.rb    | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 5c9aaa1..5af1287 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -36,7 +36,7 @@ module Yahns::ServerMP # :nodoc:
     # we'll re-trap EXIT_SIGS later for graceful shutdown iff we accept clients
     EXIT_SIGS.each { |sig| trap(sig) { exit!(0) } }
     exit!(0) if (@sig_queue & EXIT_SIGS)[0] # did we inherit sigs from parent?
-    @sig_queue = []
+    @sig_queue.clear
 
     # ignore WINCH, TTIN, TTOU, HUP in the workers
     (Yahns::Server::QUEUE_SIGS - EXIT_SIGS).each { |sig| trap(sig, nil) }
@@ -60,7 +60,7 @@ module Yahns::ServerMP # :nodoc:
     worker_nr = -1
     until (worker_nr += 1) == @worker_processes
       @workers.value?(worker_nr) and next
-      worker = Yahns::Worker.new(worker_nr)
+      worker = Yahns::Worker.new(worker_nr, @sig_queue)
       @logger.info("worker=#{worker_nr} spawning...")
       __call_hooks(@atfork_prepare, worker_nr)
       if pid = fork
diff --git a/lib/yahns/worker.rb b/lib/yahns/worker.rb
index 9b1bb8a..17bfc6e 100644
--- a/lib/yahns/worker.rb
+++ b/lib/yahns/worker.rb
@@ -5,8 +5,9 @@ class Yahns::Worker # :nodoc:
   attr_accessor :nr
   attr_reader :to_io
 
-  def initialize(nr)
+  def initialize(nr, sig_queue)
     @nr = nr
+    @sig_queue = sig_queue
     @to_io, @wr = Kgio::Pipe.new
   end
 
@@ -15,6 +16,7 @@ class Yahns::Worker # :nodoc:
   end
 
   def atfork_parent
+    @sig_queue = nil
     @to_io = @to_io.close
     self
   end
@@ -24,7 +26,7 @@ class Yahns::Worker # :nodoc:
   # dies unexpectedly.
   def yahns_step
     if @to_io.kgio_tryread(11) == nil
-      Process.kill(:QUIT, $$)
+      @sig_queue << :QUIT
       @to_io.close
     end
     :ignore
-- 
Eric Wong

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-05-09  1:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-09  1:05 [REJECT] worker: avoid signaling self for dead parent Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).