From e4388246e396be6323f1bc12c1262edd529b0520 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Tue, 16 Jul 2024 04:00:12 +0200 Subject: [PATCH] close-all-files uses too much resources Since Systemd 256~rc3-3, maxfd could be *really* big, and therefore, could take too much resources. This patch attemps to limit this. --- websockify/websockifyserver.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index 74f9f536..eaa03819 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -521,6 +521,12 @@ def daemonize(keepfd=None, chdir='/'): # Close open files maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] if maxfd == resource.RLIM_INFINITY: maxfd = 256 + # Since Systemd 256~rc3-3, maxfd could be + # *really* big, and therefore, the below code + # could take too much resources. This somehow + # attemps to limit this. + if maxfd > 4096: + maxfd = 4096 for fd in reversed(range(maxfd)): try: if fd not in keepfd: