lib/PublicInbox/Gcf2Client.pm | 20 ++++++++++++++++++-- diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm index ab486de5895ad9e5190d3438b7adb029414dfa90..4bda5520edcc94816099d93a605bf909b3d2982b 100644 --- a/lib/PublicInbox/Gcf2Client.pm +++ b/lib/PublicInbox/Gcf2Client.pm @@ -12,8 +12,8 @@ use PublicInbox::Syscall qw(EPOLLONESHOT); # fields: # async_cat => GitAsyncCat ref (read-only pipe) # sock => writable pipe to Gcf2::loop - - +# in => pipe we read from +# pid => PID of Gcf2::loop process sub new { my ($rdr) = @_; my $self = bless {}, __PACKAGE__; @@ -62,6 +62,22 @@ $self->close if !$self->{in}; # process died } no warnings 'once'; + +sub DESTROY { + my ($self) = @_; + my $pid = delete $self->{pid}; + delete $self->{in}; + return unless $pid; + eval { + PublicInbox::DS::dwaitpid($pid, undef, undef); + $self->close; # we're still in the event loop + }; + if ($@) { # wait synchronously if not in event loop + my $sock = delete $self->{sock}; + close $sock if $sock; + waitpid($pid, 0); + } +} # used by GitAsyncCat *cat_async_step = \&PublicInbox::Git::cat_async_step;