From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 15/21] lei_to_mail: reduce spew on Maildir removal
Date: Sun, 31 Jan 2021 22:28:27 -1000 [thread overview]
Message-ID: <20210201082833.3293-16-e@80x24.org> (raw)
In-Reply-To: <20210201082833.3293-1-e@80x24.org>
At most, we'll only warn once per worker when a Maildir
disappears from under us. We'll also use the '!' OpPipe
to note the exceptional condition, and use '|' to SIGPIPE
so it'll be a bit easier for hackers to remember.
---
lib/PublicInbox/LEI.pm | 8 ++++----
lib/PublicInbox/LeiToMail.pm | 12 +++++++-----
lib/PublicInbox/LeiXSearch.pm | 20 ++++++++++++--------
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index e2f22a75..17ad18b9 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -305,7 +305,8 @@ sub qerr ($;@) { $_[0]->{opt}->{quiet} or err(shift, @_) }
sub fail ($$;$) {
my ($self, $buf, $exit_code) = @_;
- err($self, $buf);
+ err($self, $buf) if defined $buf;
+ syswrite($self->{op_pipe}, '!') if $self->{op_pipe}; # fail_handler
x_it($self, ($exit_code // 1) << 8);
undef;
}
@@ -365,11 +366,10 @@ sub io_restore ($$) {
}
}
-# triggers sigpipe_handler
-sub note_sigpipe {
+sub note_sigpipe { # triggers sigpipe_handler
my ($self, $fd) = @_;
close(delete($self->{$fd})); # explicit close silences Perl warning
- syswrite($self->{op_pipe}, '!') if $self->{op_pipe};
+ syswrite($self->{op_pipe}, '|') if $self->{op_pipe};
x_it($self, 13);
}
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 01e7cec5..c6c5f84b 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -296,14 +296,14 @@ sub _buf2maildir {
my $kw = $smsg->{kw} // [];
my $sfx = join('', sort(map { $kw2char{$_} // () } @$kw));
my $rand = ''; # chosen by die roll :P
- my ($tmp, $fh, $final);
+ my ($tmp, $fh, $final, $ok);
my $common = $smsg->{blob} // _rand;
if (defined(my $pct = $smsg->{pct})) { $common .= "=$pct" }
do {
$tmp = $dst.'tmp/'.$rand.$common;
- } while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_WRONLY) &&
+ } while (!($ok = sysopen($fh, $tmp, O_CREAT|O_EXCL|O_WRONLY)) &&
$! == EEXIST && ($rand = _rand.','));
- if (print $fh $$buf and close($fh)) {
+ if ($ok && print $fh $$buf and close($fh)) {
# ignore new/ and write only to cur/, otherwise MUAs
# with R/W access to the Maildir will end up doing
# a mass rename which can take a while with thousands
@@ -316,9 +316,10 @@ sub _buf2maildir {
($rand = _rand.','));
unlink($tmp) or warn "W: failed to unlink $tmp: $!\n";
} else {
- my $err = $!;
+ my $err = "Error writing $smsg->{blob} to $dst: $!\n";
+ $_[0] = undef; # clobber dst
unlink($tmp);
- die "Error writing $smsg->{blob} to $dst: $err";
+ die $err;
}
}
@@ -329,6 +330,7 @@ sub _maildir_write_cb ($$) {
my $dst = $lei->{ovv}->{dst};
sub { # for git_to_mail
my ($buf, $smsg, $eml) = @_;
+ $dst // return $lei->fail; # dst may be undef-ed in last run
$buf //= \($eml->as_string);
return _buf2maildir($dst, $buf, $smsg) if !$dedupe;
$eml //= PublicInbox::Eml->new($$buf); # copy buf
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 4d390ee4..f630e79a 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -356,14 +356,17 @@ sub query_prepare { # called by wq_do
syswrite($lei->{op_pipe}, '.') == 1 or die "do_post_augment trigger: $!"
}
-sub sigpipe_handler { # handles SIGPIPE from l2m/lxs workers
- my ($lei) = @_;
- my $lxs = delete $lei->{lxs};
- if ($lxs && $lxs->wq_kill_old) { # is this the daemon?
- $lxs->wq_wait_old($lei);
+sub fail_handler ($;$$) {
+ my ($lei, $code, $io) = @_;
+ if (my $lxs = delete $lei->{lxs}) {
+ $lxs->wq_wait_old($lei) if $lxs->wq_kill_old; # lei-daemon
}
- close(delete $lei->{1}) if $lei->{1};
- $lei->x_it(13);
+ close($io) if $io; # needed to avoid warnings on SIGPIPE
+ $lei->x_it($code // (1 >> 8));
+}
+
+sub sigpipe_handler { # handles SIGPIPE from l2m/lxs workers
+ fail_handler($_[0], 13, delete $_[0]->{1});
}
sub do_query {
@@ -384,7 +387,8 @@ sub do_query {
$lei->event_step_init; # wait for shutdowns
my $done_op = {
'' => [ \&query_done, $lei ],
- '!' => [ \&sigpipe_handler, $lei ]
+ '|' => [ \&sigpipe_handler, $lei ],
+ '!' => [ \&fail_handler, $lei ]
};
my $in_loop = exists $lei->{sock};
$done = PublicInbox::OpPipe->new($done, $done_op, $in_loop);
next prev parent reply other threads:[~2021-02-01 8:28 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-01 8:28 [PATCH 00/21] lei2mail worker segfault finally fixed Eric Wong
2021-02-01 8:28 ` [PATCH 01/21] lei: more consistent dedupe and ovv_buf init Eric Wong
2021-02-01 8:28 ` [PATCH 02/21] ipc: switch wq to use the event loop Eric Wong
2021-02-01 8:28 ` [PATCH 03/21] lei: remove per-child SIG{__WARN__} Eric Wong
2021-02-01 8:28 ` [PATCH 04/21] lei: remove SIGPIPE handler Eric Wong
2021-02-01 8:28 ` [PATCH 05/21] ipc: more helpful ETOOMANYREFS error messages Eric Wong
2021-02-01 8:28 ` [PATCH 06/21] lei: remove syslog dependency Eric Wong
2021-02-01 8:28 ` [PATCH 07/21] sharedkv: release {dbh} before rmtree Eric Wong
2021-02-01 8:28 ` [PATCH 08/21] lei: keep $lei around until workers are reaped Eric Wong
2021-02-01 8:28 ` [PATCH 09/21] lei_dedupe: use Digest::SHA Eric Wong
2021-02-01 8:28 ` [PATCH 10/21] lei_xsearch: load PublicInbox::Smsg Eric Wong
2021-02-01 8:28 ` [PATCH 11/21] lei: deep clone {ovv} for l2m workers Eric Wong
2021-02-01 8:28 ` [PATCH 12/21] sharedkv: lock and explicitly disconnect {dbh} Eric Wong
2021-02-01 8:28 ` [PATCH 13/21] lei: increase initial timeout Eric Wong
2021-02-01 8:28 ` [PATCH 14/21] sharedkv: use lock_for_scope_fast Eric Wong
2021-02-01 8:28 ` Eric Wong [this message]
2021-02-01 8:28 ` [PATCH 16/21] sharedkv: do not set cache_size by default Eric Wong
2021-02-01 8:28 ` [PATCH 17/21] import: reap git-config(1) synchronously Eric Wong
2021-02-01 8:28 ` [PATCH 18/21] ds: guard against stack-not-refcounted quirk of Perl 5 Eric Wong
2021-02-01 9:07 ` Perl debug patches used to track down source of segfault Eric Wong
2021-02-01 8:28 ` [PATCH 19/21] ds: next_tick: avoid $_ in top-level loop iterator Eric Wong
2021-02-01 8:28 ` [PATCH 20/21] lei: avoid ETOOMANYREFS, cleanup imports Eric Wong
2021-02-01 8:28 ` [PATCH 21/21] doc: note optional BSD::Resource use Eric Wong
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: https://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=20210201082833.3293-16-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).