]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
listener: throttle errors for resource limits
authorEric Wong <e@80x24.org>
Sun, 13 Jul 2025 00:08:33 +0000 (00:08 +0000)
committerEric Wong <e@80x24.org>
Wed, 16 Jul 2025 09:20:32 +0000 (09:20 +0000)
We don't want to flood a system and run the log partition
out of space if we hit EMFILE/ENFILE/ENOMEM/ENOBUFS

lib/PublicInbox/Listener.pm

index 624756000a7a94a1eb896a80d1f1790c730e16a0..364301d0f2dc616800ff393a7c205a25deaa5fe5 100644 (file)
@@ -5,6 +5,7 @@
 package PublicInbox::Listener;
 use v5.12;
 use parent 'PublicInbox::DS';
+use PublicInbox::DS qw(now);
 use Socket qw(SOL_SOCKET SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
 use IO::Handle;
 use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE);
@@ -40,7 +41,10 @@ sub event_step {
                        # ECONNABORTED is common with bad connections
                        return;
                } elsif (my $sym = $ERR_WARN{int($!)}) {
-                       return warn "W: accept(): $! ($sym)\n";
+                       my $now = now;
+                       return if $now < ($self->{next_warn} //= 0);
+                       $self->{next_warn} = $now + 30;
+                       return warn "W: accept(".fileno($sock)."): $! ($sym)\n";
                } else {
                        return warn "BUG?: accept(): $!\n";
                }