From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/4] lei q|up|convert: common finish_output to detect errors
Date: Wed, 15 Nov 2023 09:21:45 +0000 [thread overview]
Message-ID: <20231115092145.1131822-5-e@80x24.org> (raw)
In-Reply-To: <20231115092145.1131822-1-e@80x24.org>
We need to consistently check the exit code of pigz|gzip|xz|bzip2
when writing to compressed mboxes (or bad storage).
---
lib/PublicInbox/LeiConvert.pm | 4 ++--
lib/PublicInbox/LeiToMail.pm | 11 +++++++++++
lib/PublicInbox/LeiXSearch.pm | 9 +--------
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm
index 9d2479b0..8f628562 100644
--- a/lib/PublicInbox/LeiConvert.pm
+++ b/lib/PublicInbox/LeiConvert.pm
@@ -33,9 +33,9 @@ sub process_inputs { # via wq_do
local $PublicInbox::DS::in_loop = 0; # force synchronous awaitpid
$self->SUPER::process_inputs;
my $lei = $self->{lei};
- delete $lei->{1};
my $l2m = delete $lei->{l2m};
- delete $self->{wcb}; # commit
+ delete $self->{wcb}; # may close connections
+ $l2m->finish_output($lei) if $l2m;
if (my $v2w = delete $lei->{v2w}) { $v2w->done } # may die
my $nr_w = delete($l2m->{-nr_write}) // 0;
my $d = (delete($l2m->{-nr_seen}) // 0) - $nr_w;
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 0d62888d..007191bb 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -609,6 +609,17 @@ sub _pre_augment_mbox {
undef;
}
+sub finish_output {
+ my ($self, $lei) = @_;
+ my $out = delete $lei->{1} // die 'BUG: no lei->{1}';
+ my $old = delete $lei->{old_1};
+ $lei->{1} = $old if $old;
+ return if $out->close; # reaps gzip|pigz|xz|bzip2
+ my $msg = "E: Error closing $lei->{ovv}->{dst}";
+ $? ? $lei->child_error($?) : ($msg .= " ($!)");
+ die $msg;
+}
+
sub _do_augment_mbox {
my ($self, $lei) = @_;
return unless $self->{seekable};
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 5e36c11a..cee3ad07 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -393,14 +393,7 @@ sub query_done { # EOF callback for main daemon
$lei->sto_done_request;
$lei->{ovv}->ovv_end($lei);
if ($l2m) { # close() calls LeiToMail reap_compress
- if (my $out = delete $lei->{old_1}) {
- if (my $mbout = $lei->{1}) { # compressor pipe process
- $mbout->close or die <<"";
-Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$?
-
- }
- $lei->{1} = $out;
- }
+ $l2m->finish_output($lei);
if ($l2m->lock_free) {
$l2m->poke_dst;
$lei->poke_mua;
prev parent reply other threads:[~2023-11-15 9:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-15 9:21 [PATCH 0/4] lei convert: support idempotent v2 outputs Eric Wong
2023-11-15 9:21 ` [PATCH 1/4] lei: fix idempotent STDERR redirect in workers Eric Wong
2023-11-15 9:21 ` [PATCH 2/4] lei convert: fix repeat and idempotent v2 output Eric Wong
2023-11-15 9:21 ` [PATCH 3/4] lei: avoid extra fork for v2 outputs Eric Wong
2023-11-15 9:21 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231115092145.1131822-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).