From d6674af04cb74a4efd513d938bed8bf7ab2838eb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 27 Nov 2019 01:33:33 +0000 Subject: httpd|nntpd: avoid missed signal wakeups Our attempt at using a self-pipe in signal handlers was ineffective, since pure Perl code execution is deferred and Perl doesn't use an internal self-pipe/eventfd. In retrospect, I actually prefer the simplicity of Perl in this regard... We can use sigprocmask() from Perl, so we can introduce signalfd(2) and EVFILT_SIGNAL support on Linux and *BSD-based systems, respectively. These OS primitives allow us to avoid a race where Perl checks for signals right before epoll_wait() or kevent() puts the process to sleep. The (few) systems nowadays without signalfd(2) or IO::KQueue will now see wakeups every second to avoid missed signals. --- lib/PublicInbox/DS.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 7f7cb85d..17c640f4 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -53,6 +53,7 @@ our ( $LoopTimeout, # timeout of event loop in milliseconds $DoneInit, # if we've done the one-time module init yet @Timers, # timers + $in_loop, ); Reset(); @@ -249,7 +250,7 @@ sub reap_pids { sub enqueue_reap ($) { push @$nextq, \&reap_pids }; sub EpollEventLoop { - local $SIG{CHLD} = \&enqueue_reap; + local $in_loop = 1; while (1) { my @events; my $i; @@ -628,8 +629,7 @@ sub shutdn ($) { # must be called with eval, PublicInbox::DS may not be loaded (see t/qspawn.t) sub dwaitpid ($$$) { my ($pid, $cb, $arg) = @_; - my $chld = $SIG{CHLD}; - if (defined($chld) && $chld eq \&enqueue_reap) { + if ($in_loop) { push @$WaitPids, [ $pid, $cb, $arg ]; # We could've just missed our SIGCHLD, cover it, here: -- cgit v1.2.3-24-ge0c7