From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [REJECT] worker: avoid signaling self for dead parent
Date: Fri, 9 May 2014 01:05:26 +0000 [thread overview]
Message-ID: <20140509010526.GA25397@dcvr.yhbt.net> (raw)
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
reply other threads:[~2014-05-09 1:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140509010526.GA25397@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).