From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1862F1FA42 for ; Thu, 9 Nov 2023 10:09:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699524589; bh=1KYwloZvTjehs2cQfcJYZB9Kywv/ISAEEYs99pvAFP8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XX3EFNPHtThpR1TM0sewbD2LJnB7rQzLaNerX/EcGSAQA0jDUeWVwchqhfz2WLw/x y60ey7zd21qVirQbPiJSfGXFFYXJ0dxvvu1v7CmpEsJyT0srQNg+pIiXys1oyNW+nq wyDLTPqT7Ly9H3l6zXs9Q7JqLqdkQRtPeHqDkNEk= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/13] lei: get rid of autoreap usage Date: Thu, 9 Nov 2023 10:09:45 +0000 Message-ID: <20231109100946.1440611-13-e@80x24.org> In-Reply-To: <20231109100946.1440611-1-e@80x24.org> References: <20231109100946.1440611-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can rely on Process::IO->DESTROY to close and reap in these cases. This is the final step in eliminating the wantarray invocations of popen_rd (and popen_wr). --- lib/PublicInbox/LeiInput.pm | 13 +++++-------- lib/PublicInbox/LeiRemote.pm | 14 ++++++-------- lib/PublicInbox/LeiXSearch.pm | 15 +++++++++------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm index adb356c9..68c3c459 100644 --- a/lib/PublicInbox/LeiInput.pm +++ b/lib/PublicInbox/LeiInput.pm @@ -7,7 +7,6 @@ use v5.12; use PublicInbox::DS; use PublicInbox::Spawn qw(which popen_rd); use PublicInbox::InboxWritable qw(eml_from_path); -use PublicInbox::AutoReap; # JMAP RFC 8621 4.1.1 # https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml @@ -114,15 +113,13 @@ sub handle_http_input ($$@) { push @$curl, '-s', @$curl_opt; my $cmd = $curl->for_uri($lei, $uri); $lei->qerr("# $cmd"); - my ($fh, $pid) = popen_rd($cmd, undef, { 2 => $lei->{2} }); - my $ar = PublicInbox::AutoReap->new($pid); + my $fh = popen_rd($cmd, undef, { 2 => $lei->{2} }); grep(/\A--compressed\z/, @$curl) or - $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); + $fh = IO::Uncompress::Gunzip->new($fh, + MultiStream => 1, AutoClose => 1); eval { $self->input_fh('mboxrd', $fh, $url, @args) }; - my @err = ($@ ? $@ : ()); - $ar->join; - push(@err, "\$?=$?") if $?; - $lei->child_error($?, "@$cmd failed: @err") if @err; + my $err = $@ ? ": $@" : ''; + $lei->child_error($?, "@$cmd failed$err") if $err || $?; } sub oid2eml { # git->cat_async cb diff --git a/lib/PublicInbox/LeiRemote.pm b/lib/PublicInbox/LeiRemote.pm index 54750062..559fb8d5 100644 --- a/lib/PublicInbox/LeiRemote.pm +++ b/lib/PublicInbox/LeiRemote.pm @@ -12,7 +12,6 @@ use IO::Uncompress::Gunzip; use PublicInbox::MboxReader; use PublicInbox::Spawn qw(popen_rd); use PublicInbox::LeiCurl; -use PublicInbox::AutoReap; use PublicInbox::ContentHash qw(git_sha); sub new { @@ -22,7 +21,7 @@ sub new { sub isrch { $_[0] } # SolverGit expcets this -sub _each_mboxrd_eml { # callback for MboxReader->mboxrd +sub each_mboxrd_eml { # callback for MboxReader->mboxrd my ($eml, $self) = @_; my $lei = $self->{lei}; my $xoids = $lei->{ale}->xoids_for($eml, 1); @@ -47,14 +46,13 @@ sub mset { $uri->query_form(q => $qstr, x => 'm', r => 1); # r=1: relevance my $cmd = $curl->for_uri($self->{lei}, $uri); $self->{lei}->qerr("# $cmd"); - my ($fh, $pid) = popen_rd($cmd, undef, { 2 => $lei->{2} }); - my $ar = PublicInbox::AutoReap->new($pid); $self->{smsg} = []; - $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); - PublicInbox::MboxReader->mboxrd($fh, \&_each_mboxrd_eml, $self); + my $fh = popen_rd($cmd, undef, { 2 => $lei->{2} }); + $fh = IO::Uncompress::Gunzip->new($fh, MultiStream=>1, AutoClose=>1); + eval { PublicInbox::MboxReader->mboxrd($fh, \&each_mboxrd_eml, $self) }; + my $err = $@ ? ": $@" : ''; my $wait = $self->{lei}->{sto}->wq_do('done'); - $ar->join; - $lei->child_error($?) if $?; + $lei->child_error($?, "@$cmd failed$err") if $err || $?; $self; # we are the mset (and $ibx, and $self) } diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index ba8ff293..b09c2462 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -346,14 +346,17 @@ print STDERR $_; my $cmd = $curl->for_uri($lei, $uri); $lei->qerr("# $cmd"); $rdr->{2} //= popen_wr(@lbf_tee) if @lbf_tee; - my $cfh = popen_rd($cmd, undef, $rdr); - my $fh = IO::Uncompress::Gunzip->new($cfh, MultiStream => 1); - PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, $self, - $lei, $each_smsg); + my $fh = popen_rd($cmd, undef, $rdr); + $fh = IO::Uncompress::Gunzip->new($fh, + MultiStream => 1, AutoClose => 1); + eval { + PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, + $self, $lei, $each_smsg); + }; + my ($exc, $code) = ($@, $?); $lei->sto_done_request if delete($self->{-sto_imported}); + die "E: $exc" if $exc && !$code; my $nr = delete $lei->{-nr_remote_eml} // 0; - $cfh->close; - my $code = $?; if (!$code) { # don't update if no results, maybe MTA is down $lei->{lss}->cfg_set($key, $start) if $key && $nr; mset_progress($lei, $lei->{-current_url}, $nr, $nr);