From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 608791FFAC for ; Mon, 1 Feb 2021 08:28:34 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/21] ipc: more helpful ETOOMANYREFS error messages Date: Sun, 31 Jan 2021 22:28:17 -1000 Message-Id: <20210201082833.3293-6-e@80x24.org> In-Reply-To: <20210201082833.3293-1-e@80x24.org> References: <20210201082833.3293-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: ETOOMANYREFS is probably a unfamiliar error to most users, so give a hint about RLIMIT_NOFILE. This can be hit on my system running 3 simultaneous queries with my system default limit of 1024. There's also no need to import Errno constants for uncommon errors, so we'll stop using Errno, here. We'll also try to bump RLIMIT_NOFILE as much as possible to avoid this error. --- lib/PublicInbox/IPC.pm | 6 +++--- lib/PublicInbox/LEI.pm | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 172552b9..37f02944 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -16,7 +16,6 @@ use PublicInbox::Spawn; use PublicInbox::OnDestroy; use PublicInbox::WQWorker; use Socket qw(AF_UNIX MSG_EOR SOCK_STREAM); -use Errno qw(EMSGSIZE); my $SEQPACKET = eval { Socket::SOCK_SEQPACKET() }; # portable enough? use constant PIPE_BUF => $^O eq 'linux' ? 4096 : POSIX::_POSIX_PIPE_BUF(); my $WQ_MAX_WORKERS = 4096; @@ -303,8 +302,9 @@ sub wq_do { # always async if (my $s1 = $self->{-wq_s1}) { # run in worker my $fds = [ map { fileno($_) } @$ios ]; my $n = $send_cmd->($s1, $fds, freeze([$sub, @args]), MSG_EOR); - return if defined($n); - croak "sendmsg error: $!" if $! != EMSGSIZE; + return if defined($n); # likely + croak "sendmsg: $! (check RLIMIT_NOFILE)" if $!{ETOOMANYREFS}; + croak "sendmsg: $!" if !$!{EMSGSIZE}; socketpair(my $r, my $w, AF_UNIX, SOCK_STREAM, 0) or croak "socketpair: $!"; my $buf = freeze([$sub, @args]); diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index b915bb0c..22cd20f6 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -925,6 +925,11 @@ sub lazy_start { $! = $errno; # allow interpolation to stringify in die die "connect($path): $!"; } + if (eval { require BSD::Resource }) { + my $NOFILE = BSD::Resource::RLIMIT_NOFILE(); + my ($s, $h) = BSD::Resource::getrlimit($NOFILE); + BSD::Resource::setrlimit($NOFILE, $h, $h) if $s < $h; + } umask(077) // die("umask(077): $!"); local $listener; socket($listener, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!";