]> Sergey Matveev's repositories - public-inbox.git/commitdiff
ipc: more helpful ETOOMANYREFS error messages
authorEric Wong <e@80x24.org>
Mon, 1 Feb 2021 08:28:17 +0000 (22:28 -1000)
committerEric Wong <e@80x24.org>
Mon, 1 Feb 2021 11:38:11 +0000 (11:38 +0000)
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
lib/PublicInbox/LEI.pm

index 172552b95cdf0a2ade2e4d437d98cf4e3ac6802d..37f029446ad75d13ee58257e84f76f9968874c1c 100644 (file)
@@ -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]);
index b915bb0c348f563fe811fcd87fe21e4e1e1b9aac..22cd20f6edbbf1d0a5fdfd5731a5e7250b1a70b5 100644 (file)
@@ -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: $!";