From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-1.0 required=3.0 tests=ALL_TRUSTED,AWL shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 340E12092B; Fri, 9 May 2014 01:05:26 +0000 (UTC) Date: Fri, 9 May 2014 01:05:26 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [REJECT] worker: avoid signaling self for dead parent Message-ID: <20140509010526.GA25397@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: 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