about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-02-10 08:56:41 +0000
committerEric Wong <e@80x24.org>2023-02-10 11:01:32 +0000
commit69eb1cbf5fed2a311b5692b09a8d074745fe63ac (patch)
tree0158687e65565f853fb8c6714a9240a8b12f9ec2
parent8a1708f40df5f8d367f032eef746e5390f614a50 (diff)
downloadpublic-inbox-69eb1cbf5fed2a311b5692b09a8d074745fe63ac.tar.gz
While awaitpid already registered a no-op callback in
_bidi_pipe, we can still call it again when registering it into
our event loop to ensure EPOLL_CTL_DEL fires.
-rw-r--r--lib/PublicInbox/GitAsyncCat.pm17
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm
index 49a3c602..c428f6ef 100644
--- a/lib/PublicInbox/GitAsyncCat.pm
+++ b/lib/PublicInbox/GitAsyncCat.pm
@@ -6,6 +6,7 @@
 package PublicInbox::GitAsyncCat;
 use v5.12;
 use parent qw(PublicInbox::DS Exporter);
+use PublicInbox::DS qw(awaitpid);
 use POSIX qw(WNOHANG);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
 our @EXPORT = qw(ibx_async_cat ibx_async_prefetch async_check);
@@ -21,6 +22,8 @@ sub close {
         $self->SUPER::close; # PublicInbox::DS::close
 }
 
+sub aclose { $_[1]->close } # ignore PID ($_[0])
+
 sub event_step {
         my ($self) = @_;
         my $git = $self->{git} or return;
@@ -36,12 +39,6 @@ sub event_step {
                         # ok, more to do, requeue for fairness
                         $self->requeue;
                 }
-        } elsif ((my $pid = waitpid($git->{pid}, WNOHANG)) > 0) {
-                # May happen if the child process is killed by a BOFH
-                # (or segfaults)
-                delete $git->{pid};
-                warn "E: git $pid exited with \$?=$?\n";
-                $self->close;
         }
 }
 
@@ -51,6 +48,7 @@ sub watch_cat {
                 my $self = bless { git => $git }, __PACKAGE__;
                 $git->{in}->blocking(0);
                 $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
+                awaitpid($git->{pid}, \&aclose, $self);
                 \undef; # this is a true ref()
         };
 }
@@ -83,6 +81,7 @@ sub async_check ($$$$) {
                 my $self = bless { git => $git }, 'PublicInbox::GitAsyncCheck';
                 $git->{in_c}->blocking(0);
                 $self->SUPER::new($git->{in_c}, EPOLLIN|EPOLLET);
+                awaitpid($git->{pid_c}, \&aclose, $self);
                 \undef; # this is a true ref()
         };
 }
@@ -126,12 +125,6 @@ sub event_step {
                         # ok, more to do, requeue for fairness
                         $self->requeue;
                 }
-        } elsif ((my $pid = waitpid($git->{pid_c}, WNOHANG)) > 0) {
-                # May happen if the child process is killed by a BOFH
-                # (or segfaults)
-                delete $git->{pid_c};
-                warn "E: git $pid exited with \$?=$?\n";
-                $self->close;
         }
 }