Linux NFS development
 help / color / mirror / Atom feed
* [nfs-utils PATCH] fsidd: handle accept4() failures before creating client event
@ 2026-09-03 17:50 Scott Mayhew
  0 siblings, 0 replies; only message in thread
From: Scott Mayhew @ 2026-09-03 17:50 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs

Handle failures from accept4() before creating a client event,
and add a short backoff on errors indicating resource exhaustion.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 support/reexport/fsidd.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/support/reexport/fsidd.c b/support/reexport/fsidd.c
index 51750ea3..9b80b451 100644
--- a/support/reexport/fsidd.c
+++ b/support/reexport/fsidd.c
@@ -17,6 +17,7 @@
 #include "xlog.h"
 
 static struct event_base *evbase;
+static struct event *srv_ev;
 static struct reexpdb_backend_plugin *dbbackend = &sqlite_plug_ops;
 
 /* assert_safe() always evalutes it argument, as it might have
@@ -133,21 +134,44 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
 	}
 }
 
+static void srv_reenable_cb(evutil_socket_t fd, short ev, void *d)
+{
+	(void)fd;
+	(void)ev;
+	(void)d;
+	if (srv_ev)
+		event_add(srv_ev, NULL);
+}
+
 static void srv_cb(evutil_socket_t fd, short ev, void *d)
 {
 	int cl = accept4(fd, NULL, NULL, SOCK_NONBLOCK);
 	struct event *client_ev;
+
+	if (cl == -1) {
+		if (errno == EMFILE || errno == ENFILE || errno == ENOMEM ||
+				errno == ENOBUFS) {
+			struct timeval tv = {0, 200000};
+			event_del(srv_ev);
+			event_base_once(evbase, -1, EV_TIMEOUT, srv_reenable_cb,
+					NULL, &tv);
+		}
+		return;
+	}
 	
 	(void)ev;
 	(void)d;
 
 	client_ev = event_new(evbase, cl, EV_READ | EV_PERSIST | EV_CLOSED, client_cb, event_self_cbarg());
-	event_add(client_ev, NULL);
+	if (!client_ev || event_add(client_ev, NULL) == -1) {
+		if (client_ev)
+			event_free(client_ev);
+		close(cl);
+	}
 }
 
 int main(void)
 {
-	struct event *srv_ev;
 	struct sockaddr_un addr;
 	socklen_t addr_len;
 	char *sock_file;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-03 17:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03 17:50 [nfs-utils PATCH] fsidd: handle accept4() failures before creating client event Scott Mayhew

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox