]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: force event_loop wakeup on final child death
authorEric Wong <e@80x24.org>
Mon, 25 Sep 2023 10:17:13 +0000 (10:17 +0000)
committerEric Wong <e@80x24.org>
Mon, 25 Sep 2023 23:14:44 +0000 (23:14 +0000)
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
lib/PublicInbox/LEI.pm
lib/PublicInbox/XapHelper.pm

index 919a4b67f34a1d7327951b75d4f425d2b431673b..49550b2be4a37e88042054865539b9a2dede2feb 100644 (file)
@@ -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 ($!)");
                }
        }
 }
index be77fa907849f510a8faad7f6b4758a4823aac5a..432ae61ea887a8784ae225e5eab0bf48e0b589b0 100644 (file)
@@ -1316,7 +1316,6 @@ sub lazy_start {
                        # closing eof_p triggers \&noop wakeup
                        $listener = $eof_p = $pil = $path = undef;
                        $lis->close; # DS::close
-                       PublicInbox::DS->SetLoopTimeout(1000);
                };
        };
        my $sig = {
index e8eeb2dceb2c46804739835dd0e659e54fc991fa..8c2b86d60b4886b97e06fa610a4887d2472d076c 100644 (file)
@@ -209,7 +209,6 @@ sub reap_worker { # awaitpid CB
        delete $WORKERS{$nr};
        if (($? >> 8) == 66) { # EX_NOINPUT
                $alive = undef;
-               PublicInbox::DS->SetLoopTimeout(1);
        } elsif ($?) {
                warn "worker[$nr] died \$?=$?\n";
        }