user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 12/13] lei: get rid of autoreap usage
  2023-11-09 10:09  7% [PATCH 00/13] misc error handling stuff and simplifications Eric Wong
@ 2023-11-09 10:09  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-11-09 10:09 UTC (permalink / raw)
  To: meta

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);

^ permalink raw reply related	[relevance 6%]

* [PATCH 00/13] misc error handling stuff and simplifications
@ 2023-11-09 10:09  7% Eric Wong
  2023-11-09 10:09  6% ` [PATCH 12/13] lei: get rid of autoreap usage Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-11-09 10:09 UTC (permalink / raw)
  To: meta

1-4 were things I noticed while chasing the lei SIGPIPE handling
fix.  5-7 are things I noticed while testing on Dragonfly and
NetBSD.  8 was noticed randomly while working on a new mirror,
and the last few complete the work which let me get rid of tied
IO handles in favor of using the PublicInbox::IO subclass.

Eric Wong (13):
  lei_xsearch: put query in process title for debugging
  lei: use cached $daemon_pid when possible
  lei: reuse FDs atfork and close explicitly
  lei_up: use v5.12
  net_nntp_socks: more comments around how it works
  lei ls-mail-source: gracefully handle network failures
  net: retry on EINTR and check for {quit} flag
  lei_mirror: note missing local manifests are non-fatal
  ipc: simplify partial sendmsg fallback
  lei_input: always close single `eml' inputs
  xapcmd: get rid of scalar wantarray popen_rd
  lei: get rid of autoreap usage
  spawn: get rid of wantarray popen_rd/popen_wr

 lib/PublicInbox/IPC.pm             | 13 ++------
 lib/PublicInbox/LEI.pm             | 11 ++++---
 lib/PublicInbox/LeiInput.pm        | 26 +++++++--------
 lib/PublicInbox/LeiLsMailSource.pm |  6 ++--
 lib/PublicInbox/LeiMirror.pm       |  5 +--
 lib/PublicInbox/LeiRemote.pm       | 14 ++++----
 lib/PublicInbox/LeiUp.pm           | 10 +++---
 lib/PublicInbox/LeiXSearch.pm      | 27 ++++++++-------
 lib/PublicInbox/NetNNTPSocks.pm    | 12 ++++---
 lib/PublicInbox/NetReader.pm       | 53 +++++++++++++++++++++---------
 lib/PublicInbox/Spawn.pm           |  6 ++--
 lib/PublicInbox/TestCommon.pm      | 23 ++++++++++++-
 lib/PublicInbox/Watch.pm           |  2 +-
 lib/PublicInbox/Xapcmd.pm          | 12 +++----
 t/io.t                             |  8 +----
 t/ipc.t                            |  7 ++++
 t/lei-import.t                     | 27 +++++++++++++++
 17 files changed, 163 insertions(+), 99 deletions(-)

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-11-09 10:09  7% [PATCH 00/13] misc error handling stuff and simplifications Eric Wong
2023-11-09 10:09  6% ` [PATCH 12/13] lei: get rid of autoreap usage Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).