X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FGcf2Client.pm;h=2022293d6b0a4684c6d72adf74e6413a426fc0bf;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=4bda5520edcc94816099d93a605bf909b3d2982b;hpb=ff91a3b8ba82d1d39dfd6b6ba18ba3134133693b;p=public-inbox.git diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm index 4bda5520..2022293d 100644 --- a/lib/PublicInbox/Gcf2Client.pm +++ b/lib/PublicInbox/Gcf2Client.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ # connects public-inbox processes to PublicInbox::Gcf2::loop() @@ -9,11 +9,13 @@ use PublicInbox::Git; use PublicInbox::Spawn qw(popen_rd); use IO::Handle (); use PublicInbox::Syscall qw(EPOLLONESHOT); +use PublicInbox::DS qw(dwaitpid); # 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 +# owner_pid => process which spawned {pid} sub new { my ($rdr) = @_; my $self = bless {}, __PACKAGE__; @@ -24,6 +26,7 @@ sub new { $rdr //= {}; $rdr->{0} = $out_r; my $cmd = [$^X, qw[-MPublicInbox::Gcf2 -e PublicInbox::Gcf2::loop()]]; + $self->{owner_pid} = $$; @$self{qw(in pid)} = popen_rd($cmd, $env, $rdr); fcntl($out_w, 1031, 4096) if $^O eq 'linux'; # 1031: F_SETPIPE_SZ $out_w->autoflush(1); @@ -65,17 +68,12 @@ 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); + # GitAsyncCat::event_step may reap us with WNOHANG, too + my $pid = delete $self->{pid} or return; + if ($$ == $self->{owner_pid}) { + PublicInbox::DS->in_loop ? $self->close : delete($self->{sock}); + dwaitpid $pid; } }