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.
This commit is contained in:
Thomas Goirand 2024-07-16 04:00:12 +02:00
parent 99f83ca083
commit e4388246e3
1 changed files with 6 additions and 0 deletions

View File

@ -521,6 +521,12 @@ class WebSockifyServer():
# Close open files # Close open files
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
if maxfd == resource.RLIM_INFINITY: maxfd = 256 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)): for fd in reversed(range(maxfd)):
try: try:
if fd not in keepfd: if fd not in keepfd: