about summary refs log tree commit homepage
path: root/lib/PublicInbox/DS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-09-25 10:17:13 +0000
committerEric Wong <e@80x24.org>2023-09-25 23:14:44 +0000
commit8addd1ec64c6e8b4b49e6a4dc8884fd2ee65fe49 (patch)
treee505527752aa40f3c3483ed56b5575cea5188eaf /lib/PublicInbox/DS.pm
parent9e49a6ebc0dfcb63fd6e9a79ea52be5c0f41b123 (diff)
downloadpublic-inbox-8addd1ec64c6e8b4b49e6a4dc8884fd2ee65fe49.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/DS.pm')
-rw-r--r--lib/PublicInbox/DS.pm9
1 files changed, 6 insertions, 3 deletions
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 ($!)");
                 }
         }
 }