]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
listener: don't set listen backlog on inherited sockets
authorEric Wong <e@80x24.org>
Wed, 5 Mar 2025 00:45:36 +0000 (00:45 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Mar 2025 19:23:03 +0000 (19:23 +0000)
By using the listen(2) backlog as-is when inheriting (from
systemd or similar), we can give the sysadmin more control on
controlling overload on a per-listener basis.  For systemd
users, this means the `Backlog=' parameter in systemd.socket(5)
can be respected and configured to give certain sockets a
smaller backlog (perhaps combined with with per-listener
`multi-accept' parameter on sockets with the standard (huge)
backlog).

For sockets we create, continue to use INT_MAX and let the
kernel clamp it to whatever system-wide limit there is
(e.g. `net.core.somaxconn' sysctl on Linux).

lib/PublicInbox/Daemon.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/Listener.pm

index 5d93f81fe45170ddafc95045a059591652aa5730..8fe93acde01e40eae036a3d57a90f904c7914d95 100644 (file)
@@ -264,7 +264,7 @@ EOF
                        die $@ if $@;
                        %o = (LocalAddr => $l, ReuseAddr => 1, Proto => 'tcp');
                }
-               $o{Listen} = 1024;
+               $o{Listen} = 2**31 - 1; # kernel will clamp
                my $prev = umask 0000;
                my $s = eval { $sock_pkg->new(%o) } or
                        warn "error binding $l: $! ($@)\n";
index 94bac688596bb9e759a918064ea7fc3c95236e61..0a779c4fbfd513c1538f1a0accc22e0181cde668 100644 (file)
@@ -9,7 +9,7 @@ package PublicInbox::LEI;
 use v5.12;
 use parent qw(PublicInbox::DS PublicInbox::LeiExternal
        PublicInbox::LeiQuery);
-use autodie qw(bind chdir open pipe socket socketpair syswrite unlink);
+use autodie qw(bind chdir listen open pipe socket socketpair syswrite unlink);
 use Getopt::Long ();
 use Socket qw(AF_UNIX SOCK_SEQPACKET pack_sockaddr_un);
 use Errno qw(EPIPE EAGAIN ECONNREFUSED ENOENT ECONNRESET EINTR);
@@ -1371,6 +1371,7 @@ sub lazy_start {
        local (%PATH2CFG, $MDIR2CFGPATH);
        local $daemon_pid = $$;
        $listener->blocking(0);
+       listen $listener, 2**31 - 1; # kernel will clamp
        my $exit_code;
        my $pil = PublicInbox::Listener->new($listener, \&accept_dispatch);
        local $quit = do {
index c83901b2afb2d69d6ae6e6c5b80a50375bd249b2..624756000a7a94a1eb896a80d1f1790c730e16a0 100644 (file)
@@ -21,7 +21,6 @@ sub new {
        my ($class, $s, $cb, $multi_accept) = @_;
        setsockopt($s, SOL_SOCKET, SO_KEEPALIVE, 1);
        setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1); # ignore errors on non-TCP
-       listen($s, 2**31 - 1); # kernel will clamp
        my $self = bless { post_accept => $cb }, $class;
        $self->{multi_accept} = $multi_accept //= $MULTI_ACCEPT;
        $self->SUPER::new($s, EPOLLIN|EPOLLEXCLUSIVE);