From bcf0a9ac5846653a548db59696bacd86fa8e1e02 Mon Sep 17 00:00:00 2001 From: Kamil Monicz Date: Sun, 27 Sep 2026 08:22:48 +0200 Subject: [PATCH] socket-proxyd: raise RLIMIT_NOFILE at startup Each proxied connection uses eight file descriptors: the accepted and the outgoing socket, a duplicate of each, and a pipe for each direction. With the default soft RLIMIT_NOFILE of 1024, setting up forwarding fails with "Too many open files" at about 127 concurrent connections, well before the default --connections-max=256, and the connection is closed right after being accepted. socket-proxyd's I/O is sd-event based and handles fds above 1023, so it does not need the select()-compatible soft limit. Call rlimit_nofile_bump(-1) at startup to raise RLIMIT_NOFILE as far as permitted, like udevd does. (cherry picked from commit 98752540be47778e253cbafe51c7ccdd30f4995e) --- src/socket-proxy/socket-proxyd.c | 5 +++++ test/units/TEST-74-AUX-UTILS.socket-proxyd.sh | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index 94a42e1cab..ad56ac72b2 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -21,6 +21,7 @@ #include "main-func.h" #include "parse-util.h" #include "resolve-private.h" +#include "rlimit-util.h" #include "set.h" #include "socket-forward.h" #include "socket-util.h" @@ -563,6 +564,10 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; + /* Each connection holds several fds (two sockets, their duplicates and a pipe per direction), so + * the default soft limit of 1024 would run out well before the default connection limit. */ + (void) rlimit_nofile_bump(-1); + r = sd_event_default(&context.event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); diff --git a/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh b/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh index c028747ec0..0767e27268 100755 --- a/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh +++ b/test/units/TEST-74-AUX-UTILS.socket-proxyd.sh @@ -38,6 +38,8 @@ EOF cat >/run/systemd/system/test-proxyd.service <