]> Sergey Matveev's repositories - public-inbox.git/commitdiff
ds: awaitpid: do not clobber entries for reaped processes
authorEric Wong <e@80x24.org>
Sat, 21 Jan 2023 08:58:19 +0000 (08:58 +0000)
committerEric Wong <e@80x24.org>
Sat, 21 Jan 2023 16:33:22 +0000 (16:33 +0000)
We must only write to $AWAIT_PIDS on the initial reap attempt.
While we're at it, avoid triggering an extra wakeup if we're
doing synchronous awaitpid.  This seems to eliminate most
reliance on Qspawn->DESTROY to call Qspawn->finalize.

lib/PublicInbox/DS.pm

index 523d47e4255ecf9fea2d7dab9aec756364febc24..0a763d0ef643ad0d5c5deb8e027b9df67d4438ae 100644 (file)
@@ -699,8 +699,8 @@ sub long_response ($$;@) {
 }
 
 sub awaitpid {
-       my ($pid, @cb_args) = @_;
-       $AWAIT_PIDS->{$pid} //= @cb_args ? \@cb_args : 0;
+       my ($pid, @cb_args) = @_; # @cb_args = ($cb, @args), $cb may be undef
+       $AWAIT_PIDS->{$pid} = \@cb_args if @cb_args;
        # provide synchronous API
        if (defined(wantarray) || (!$in_loop && !@cb_args)) {
                my $ret;
@@ -716,9 +716,9 @@ again:
                        delete $AWAIT_PIDS->{$pid};
                }
                return $ret;
+       } elsif ($in_loop) { # We could've just missed our SIGCHLD, cover it, here:
+               enqueue_reap();
        }
-       # We could've just missed our SIGCHLD, cover it, here:
-       enqueue_reap() if $in_loop;
 }
 
 1;