about summary refs log tree commit homepage
path: root/lib/PublicInbox/Gcf2Client.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-31 13:51:45 +0000
committerEric Wong <e@80x24.org>2021-01-01 05:00:39 +0000
commitff91a3b8ba82d1d39dfd6b6ba18ba3134133693b (patch)
tree5319f235174100dcacc4a65ea6d589c8f696cfc1 /lib/PublicInbox/Gcf2Client.pm
parent0308b7313856713a539dde078048c755334f9ae2 (diff)
downloadpublic-inbox-ff91a3b8ba82d1d39dfd6b6ba18ba3134133693b.tar.gz
We don't want to leave Xapcmd waitpid(-1, ...) call to hit it.
Diffstat (limited to 'lib/PublicInbox/Gcf2Client.pm')
-rw-r--r--lib/PublicInbox/Gcf2Client.pm20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm
index ab486de5..4bda5520 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__;
@@ -63,6 +63,22 @@ sub event_step {
 
 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;