* [PATCH 3/5] send_cmd4: make `tries' a per-call parameter
2024-04-25 21:31 6% [PATCH 0/5] xap_helper stuff for public daemons Eric Wong
@ 2024-04-25 21:31 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2024-04-25 21:31 UTC (permalink / raw)
To: meta
While existing callers are private (lei, *-index, -watch) are
private, we should not be blocking the event loop in
public-facing servers when we hit ETOOMANYREFS, ENOMEM, or
ENOBUFS.
---
lib/PublicInbox/CmdIPC4.pm | 12 ++++++------
lib/PublicInbox/Spawn.pm | 12 +++++++-----
lib/PublicInbox/Syscall.pm | 8 ++++----
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/CmdIPC4.pm b/lib/PublicInbox/CmdIPC4.pm
index 2f102ec6..fc77bd03 100644
--- a/lib/PublicInbox/CmdIPC4.pm
+++ b/lib/PublicInbox/CmdIPC4.pm
@@ -11,8 +11,8 @@ use Socket qw(SOL_SOCKET SCM_RIGHTS);
sub sendmsg_retry ($) {
return 1 if $!{EINTR};
return unless ($!{ENOMEM} || $!{ENOBUFS} || $!{ETOOMANYREFS});
- return if ++$_[0] >= 50;
- warn "# sleeping on sendmsg: $! (#$_[0])\n";
+ return if --$_[0] < 0;
+ warn "# sleeping on sendmsg: $! ($_[0] tries left)\n";
select(undef, undef, undef, 0.1);
1;
}
@@ -22,15 +22,15 @@ require Socket::MsgHdr; # XS
no warnings 'once';
# any number of FDs per-sendmsg(2) + buffer
-*send_cmd4 = sub ($$$$) { # (sock, fds, buf, flags) = @_;
- my ($sock, $fds, undef, $flags) = @_;
+*send_cmd4 = sub ($$$$;$) { # (sock, fds, buf, flags) = @_;
+ my ($sock, $fds, undef, $flags, $tries) = @_;
+ $tries //= 50;
my $mh = Socket::MsgHdr->new(buf => $_[2]);
$mh->cmsghdr(SOL_SOCKET, SCM_RIGHTS, pack('i' x scalar(@$fds), @$fds));
my $s;
- my $try = 0;
do {
$s = Socket::MsgHdr::sendmsg($sock, $mh, $flags);
- } while (!defined($s) && sendmsg_retry($try));
+ } while (!defined($s) && sendmsg_retry($tries));
$s;
};
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index e36659ce..e9e81e88 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -176,15 +176,15 @@ out:
return (int)pid;
}
-static int sendmsg_retry(unsigned *tries)
+static int sendmsg_retry(int *tries)
{
const struct timespec req = { 0, 100000000 }; /* 100ms */
int err = errno;
switch (err) {
case EINTR: PERL_ASYNC_CHECK(); return 1;
case ENOBUFS: case ENOMEM: case ETOOMANYREFS:
- if (++*tries >= 50) return 0;
- fprintf(stderr, "# sleeping on sendmsg: %s (#%u)\n",
+ if (--*tries < 0) return 0;
+ fprintf(stderr, "# sleeping on sendmsg: %s (%d tries left)\n",
strerror(err), *tries);
nanosleep(&req, NULL);
PERL_ASYNC_CHECK();
@@ -201,7 +201,7 @@ union my_cmsg {
char pad[sizeof(struct cmsghdr) + 16 + SEND_FD_SPACE];
};
-SV *send_cmd4(PerlIO *s, SV *svfds, SV *data, int flags)
+SV *send_cmd4_(PerlIO *s, SV *svfds, SV *data, int flags, int tries)
{
struct msghdr msg = { 0 };
union my_cmsg cmsg = { 0 };
@@ -211,7 +211,6 @@ SV *send_cmd4(PerlIO *s, SV *svfds, SV *data, int flags)
AV *fds = (AV *)SvRV(svfds);
I32 i, nfds = av_len(fds) + 1;
int *fdp;
- unsigned tries = 0;
if (SvOK(data)) {
iov.iov_base = SvPV(data, dlen);
@@ -332,6 +331,9 @@ EOM
if (defined $all_libc) { # set for Gcf2
$ENV{PERL_INLINE_DIRECTORY} = $inline_dir;
%RLIMITS = rlimit_map();
+ *send_cmd4 = sub ($$$$;$) {
+ send_cmd4_($_[0], $_[1], $_[2], $_[3], 50);
+ }
} else {
require PublicInbox::SpawnPP;
*pi_fork_exec = \&PublicInbox::SpawnPP::pi_fork_exec
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index 99af5bf5..4cbe9623 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -467,8 +467,8 @@ if (defined($SYS_sendmsg) && defined($SYS_recvmsg)) {
no warnings 'once';
require PublicInbox::CmdIPC4;
-*send_cmd4 = sub ($$$$) {
- my ($sock, $fds, undef, $flags) = @_;
+*send_cmd4 = sub ($$$$;$) {
+ my ($sock, $fds, undef, $flags, $tries) = @_;
my $iov = pack('P'.TMPL_size_t,
$_[2] // NUL, length($_[2] // NUL) || 1);
my $fd_space = scalar(@$fds) * SIZEOF_int;
@@ -487,10 +487,10 @@ require PublicInbox::CmdIPC4;
$msg_controllen,
0); # msg_flags
my $s;
- my $try = 0;
+ $tries //= 50;
do {
$s = syscall($SYS_sendmsg, fileno($sock), $mh, $flags);
- } while ($s < 0 && PublicInbox::CmdIPC4::sendmsg_retry($try));
+ } while ($s < 0 && PublicInbox::CmdIPC4::sendmsg_retry($tries));
$s >= 0 ? $s : undef;
};
^ permalink raw reply related [relevance 7%]
* [PATCH 0/5] xap_helper stuff for public daemons
@ 2024-04-25 21:31 6% Eric Wong
2024-04-25 21:31 7% ` [PATCH 3/5] send_cmd4: make `tries' a per-call parameter Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2024-04-25 21:31 UTC (permalink / raw)
To: meta
1 and 2 are trivial fixes.
3 and 4 makes failures more graceful when dealing with resource
exhaustion.
5 allows configuring the Xapian helper processes from the
top-level daemon and reverts to disabling helpers by default.
Eric Wong (5):
t/cindex: require DBD::SQLite for now
www: mbox*: use Perl 5.12
send_cmd4: make `tries' a per-call parameter
search: async_mset: pass resource errors to callback
daemon: share and allow configuring Xapian helpers
Documentation/public-inbox-daemon.pod | 38 +++++++++++++++++++++++++--
Makefile.PL | 6 +++++
lib/PublicInbox/CmdIPC4.pm | 12 ++++-----
lib/PublicInbox/Daemon.pm | 24 +++++++++++++++--
lib/PublicInbox/Mbox.pm | 2 +-
lib/PublicInbox/MboxGz.pm | 2 +-
lib/PublicInbox/Search.pm | 16 ++++++-----
lib/PublicInbox/Spawn.pm | 12 +++++----
lib/PublicInbox/Syscall.pm | 8 +++---
lib/PublicInbox/TestCommon.pm | 9 ++++++-
lib/PublicInbox/XapClient.pm | 7 ++---
t/cindex.t | 2 +-
12 files changed, 106 insertions(+), 32 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2024-04-25 21:31 6% [PATCH 0/5] xap_helper stuff for public daemons Eric Wong
2024-04-25 21:31 7% ` [PATCH 3/5] send_cmd4: make `tries' a per-call parameter 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).