user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] listener: warn on some accept()/accept4() errors
Date: Tue,  1 Oct 2019 23:18:02 +0000	[thread overview]
Message-ID: <20191001231802.660-1-e@80x24.org> (raw)

We need to warn when hitting file or socket memory limits
or misconfigurations which clear O_NONBLOCK to make it easier
to diagnose configuration problems.  We'll also warn on
some other errors in case bugs creep in...
---
 lib/PublicInbox/Listener.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm
index f6a5da69..821c3458 100644
--- a/lib/PublicInbox/Listener.pm
+++ b/lib/PublicInbox/Listener.pm
@@ -10,6 +10,13 @@ use Socket qw(SOL_SOCKET SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
 use fields qw(post_accept);
 require IO::Handle;
 use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET);
+use Errno qw(EAGAIN ECONNABORTED EPERM);
+
+# Warn on transient errors, mostly resource limitations.
+# EINTR would indicate the failure to set NonBlocking in systemd or similar
+my %ERR_WARN = map {;
+	eval("Errno::$_()") => $_
+} qw(EMFILE ENFILE ENOBUFS ENOMEM EINTR);
 
 sub new ($$$) {
 	my ($class, $s, $cb) = @_;
@@ -35,6 +42,18 @@ sub event_step {
 		IO::Handle::blocking($c, 0); # no accept4 :<
 		$self->{post_accept}->($c, $addr, $sock);
 		$self->requeue;
+	} elsif ($! == EAGAIN || $! == ECONNABORTED || $! == EPERM) {
+		# EAGAIN is common and likely
+		# ECONNABORTED is common with bad connections
+		# EPERM happens if firewall rules prevent a connection
+		# on Linux (and everything that emulates Linux).
+		# Firewall rules are sometimes intentional, so we don't
+		# warn on EPERM to avoid being too noisy...
+		return;
+	} elsif (my $sym = $ERR_WARN{int($!)}) {
+		warn "W: accept(): $! ($sym)\n";
+	} else {
+		warn "BUG?: accept(): $!\n";
 	}
 }
 
-- 
EW


                 reply	other threads:[~2019-10-01 23:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191001231802.660-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).