]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Gcf2Client.pm
use PublicInbox::DS for dwaitpid
[public-inbox.git] / lib / PublicInbox / Gcf2Client.pm
index ab486de5895ad9e5190d3438b7adb029414dfa90..10820852b21d02761a49048b1dc31e8bc9f597cd 100644 (file)
@@ -9,11 +9,12 @@ 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
 sub new  {
        my ($rdr) = @_;
        my $self = bless {}, __PACKAGE__;
@@ -63,6 +64,15 @@ sub event_step {
 
 no warnings 'once';
 
+sub DESTROY {
+       my ($self) = @_;
+       delete $self->{in};
+       # GitAsyncCat::event_step may reap us with WNOHANG, too
+       my $pid = delete $self->{pid} or return;
+       PublicInbox::DS->in_loop ? $self->close : delete($self->{sock});
+       dwaitpid $pid;
+}
+
 # used by GitAsyncCat
 *cat_async_step = \&PublicInbox::Git::cat_async_step;