* [PATCH 20/21] lei: avoid ETOOMANYREFS, cleanup imports
2021-02-01 8:28 7% [PATCH 00/21] lei2mail worker segfault finally fixed Eric Wong
@ 2021-02-01 8:28 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-02-01 8:28 UTC (permalink / raw)
To: meta
As with PublicInbox::IPC, we'll attempt to bump RLIMIT_NOFILE
and transparently workaround ETOOMANYREFS. If that fails,
we'll give the user a hint to bump RLIMIT_NOFILE since
ETOOMANYREFS is an uncommon error which users may be unfamiliar
with.
Found while stress testing for segfaults.
---
script/lei | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/script/lei b/script/lei
index f92dd302..58f0dbe9 100755
--- a/script/lei
+++ b/script/lei
@@ -4,10 +4,9 @@
use strict;
use v5.10.1;
use Socket qw(AF_UNIX SOCK_SEQPACKET MSG_EOR pack_sockaddr_un);
-use Errno qw(EINTR ECONNRESET);
use PublicInbox::CmdIPC4;
my $narg = 5;
-my ($sock, $pwd);
+my $sock;
my $recv_cmd = PublicInbox::CmdIPC4->can('recv_cmd4');
my $send_cmd = PublicInbox::CmdIPC4->can('send_cmd4') // do {
require PublicInbox::Spawn; # takes ~50ms even if built *sigh*
@@ -73,20 +72,32 @@ connect($path): $! (after attempted daemon start)
Falling back to (slow) one-shot mode
}
- 1;
-}) { # (Socket::MsgHdr|Inline::C), $sock, $pwd are all available:
+ # (Socket::MsgHdr|Inline::C), $sock are all available:
open my $dh, '<', '.' or die "open(.) $!";
my $buf = join("\0", scalar(@ARGV), @ARGV);
while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
$buf .= "\0\0";
- $send_cmd->($sock, [ 0, 1, 2, fileno($dh) ], $buf, MSG_EOR) or
- die "sendmsg: $!";
+ my $n = $send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR);
+ if (!$n && $!{ETOOMANYREFS} && eval { require BSD::Resource }) {
+ my $NOFILE = BSD::Resource::RLIMIT_NOFILE();
+ my ($s, $h) = BSD::Resource::getrlimit($NOFILE);
+ if ($s < $h && BSD::Resource::setrlimit($NOFILE, $h, $h)) {
+ $n = $send_cmd->($sock, [0, 1, 2, fileno($dh)],
+ $buf, MSG_EOR);
+ }
+ }
+ if (!$n) {
+ die "sendmsg: $! (check RLIMIT_NOFILE)\n" if $!{ETOOMANYREFS};
+ die "sendmsg: $!\n";
+ }
+ 1;
+}) { # connected and request sent to lei-daemon, wait for responses or EOF
my $x_it_code = 0;
while (1) {
- my (@fds) = $recv_cmd->($sock, $buf, 4096 * 33);
+ my (@fds) = $recv_cmd->($sock, my $buf, 4096 * 33);
if (scalar(@fds) == 1 && !defined($fds[0])) {
- last if $! == ECONNRESET;
- next if $! == EINTR;
+ next if $!{EINTR};
+ last if $!{ECONNRESET};
die "recvmsg: $!";
}
last if $buf eq '';
^ permalink raw reply related [relevance 6%]
* [PATCH 00/21] lei2mail worker segfault finally fixed
@ 2021-02-01 8:28 7% Eric Wong
2021-02-01 8:28 6% ` [PATCH 20/21] lei: avoid ETOOMANYREFS, cleanup imports Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-02-01 8:28 UTC (permalink / raw)
To: meta
This lei2mail segfault turned out to be an old Perl 5 quirk
which plagued many before me. It was not consistently
reproducible, and random changes seemed to make it happen more
or less frequently. There were several times when I thought I
fixed it (and maybe this is still one of them!) only to have it
pop up again.
Still, I found many other little bugs and improvements worth
doing along the way. Hope things go more smoothly in the
future...
Anyways, [PATCH 18/21] is the fix (and I'll followup with more
on how I found the fix). 19/21 is purely defensive
future-proofing.
Eric Wong (21):
lei: more consistent dedupe and ovv_buf init
ipc: switch wq to use the event loop
lei: remove per-child SIG{__WARN__}
lei: remove SIGPIPE handler
ipc: more helpful ETOOMANYREFS error messages
lei: remove syslog dependency
sharedkv: release {dbh} before rmtree
lei: keep $lei around until workers are reaped
lei_dedupe: use Digest::SHA
lei_xsearch: load PublicInbox::Smsg
lei: deep clone {ovv} for l2m workers
sharedkv: lock and explicitly disconnect {dbh}
lei: increase initial timeout
sharedkv: use lock_for_scope_fast
lei_to_mail: reduce spew on Maildir removal
sharedkv: do not set cache_size by default
import: reap git-config(1) synchronously
ds: guard against stack-not-refcounted quirk of Perl 5
ds: next_tick: avoid $_ in top-level loop iterator
lei: avoid ETOOMANYREFS, cleanup imports
doc: note optional BSD::Resource use
Documentation/public-inbox-config.pod | 2 +-
INSTALL | 6 ++
MANIFEST | 2 +
lib/PublicInbox/DS.pm | 12 ++--
lib/PublicInbox/IPC.pm | 43 +++++++-----
lib/PublicInbox/Import.pm | 1 +
lib/PublicInbox/LEI.pm | 95 +++++++++++++++------------
lib/PublicInbox/LeiDedupe.pm | 6 +-
lib/PublicInbox/LeiExternal.pm | 3 +-
lib/PublicInbox/LeiOverview.pm | 51 +++++++-------
lib/PublicInbox/LeiToMail.pm | 84 +++++++++++------------
lib/PublicInbox/LeiXSearch.pm | 36 +++++-----
lib/PublicInbox/Lock.pm | 17 +++++
lib/PublicInbox/SharedKV.pm | 33 +++++++---
lib/PublicInbox/WQWorker.pm | 34 ++++++++++
script/lei | 28 +++++---
t/lei_to_mail.t | 31 +++++----
xt/stress-sharedkv.t | 50 ++++++++++++++
18 files changed, 342 insertions(+), 192 deletions(-)
create mode 100644 lib/PublicInbox/WQWorker.pm
create mode 100644 xt/stress-sharedkv.t
^ 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 --
2021-02-01 8:28 7% [PATCH 00/21] lei2mail worker segfault finally fixed Eric Wong
2021-02-01 8:28 6% ` [PATCH 20/21] lei: avoid ETOOMANYREFS, cleanup imports 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).