about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-31 22:28:17 -1000
committerEric Wong <e@80x24.org>2021-02-01 11:38:11 +0000
commit620215dbaa63ecb04923bb29a1ed78606286c192 (patch)
tree13be0f26cbf8d393dc8d8c50309da11feed57443 /lib
parent21ce1a28915374297829bd05feda0cea52adb324 (diff)
downloadpublic-inbox-620215dbaa63ecb04923bb29a1ed78606286c192.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/IPC.pm6
-rw-r--r--lib/PublicInbox/LEI.pm5
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: $!";