From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 81A2420068 for ; Thu, 31 Dec 2020 13:51:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 27/36] gcf2client: reap process on DESTROY Date: Thu, 31 Dec 2020 13:51:45 +0000 Message-Id: <20201231135154.6070-28-e@80x24.org> In-Reply-To: <20201231135154.6070-1-e@80x24.org> References: <20201231135154.6070-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We don't want to leave Xapcmd waitpid(-1, ...) call to hit it. --- lib/PublicInbox/Gcf2Client.pm | 20 ++++++++++++++++++-- 1 file 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;