From 8addd1ec64c6e8b4b49e6a4dc8884fd2ee65fe49 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 25 Sep 2023 10:17:13 +0000 Subject: ds: force event_loop wakeup on final child death Reaping children needs to keep the event_loop spinning another round when the @post_loop_do callback may be used to check on process exit during shutdown. This allows us to get rid of the hacky SetLoopTimeout calls in lei-daemon and XapHelper.pm during process shutdown if we're trying to wait for all PIDs to exit before leaving the event loop. --- lib/PublicInbox/DS.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 919a4b67..49550b2b 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -216,12 +216,15 @@ sub await_cb ($;@) { sub reap_pids { $reap_armed = undef; while (1) { - my $pid = waitpid(-1, WNOHANG) // last; - last if $pid <= 0; + my $pid = waitpid(-1, WNOHANG) or return; if (defined(my $cb_args = delete $AWAIT_PIDS->{$pid})) { await_cb($pid, @$cb_args) if $cb_args; - } else { + } elsif ($pid == -1 && $! == ECHILD) { + return requeue(\&dflush); # force @post_loop_do to run + } elsif ($pid > 0) { warn "W: reaped unknown PID=$pid: \$?=$?\n"; + } else { # does this happen? + return warn("W: waitpid(-1, WNOHANG) => $pid ($!)"); } } } -- cgit v1.2.3-24-ge0c7