From df885586d490d1149efda1b59269c69e7185549f Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Wed, 19 Feb 2020 15:28:12 -0500 Subject: [PATCH] close Popen() pipes explicitly for PyPy Waiting for garbage collection to close pipes opened by Popen() can lead to "Too many open files" errors with PyPy; close them explicitly. --- ChangeLog | 1 + fail2ban/server/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea0c4a64..007e4ffc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,7 @@ ver. 0.10.6-dev (20??/??/??) - development edition IPv6-capable now. ### Fixes +* restoring a large number (500+ depending on files ulimit) of current bans when using PyPy fixed ### New Features diff --git a/fail2ban/server/utils.py b/fail2ban/server/utils.py index 2bde3f4d..8e8b0571 100644 --- a/fail2ban/server/utils.py +++ b/fail2ban/server/utils.py @@ -260,7 +260,6 @@ class Utils(): if stdout is not None and stdout != '' and std_level >= logSys.getEffectiveLevel(): for l in stdout.splitlines(): logSys.log(std_level, "%x -- stdout: %r", realCmdId, uni_decode(l)) - popen.stdout.close() if popen.stderr: try: if retcode is None or retcode < 0: @@ -271,7 +270,8 @@ class Utils(): if stderr is not None and stderr != '' and std_level >= logSys.getEffectiveLevel(): for l in stderr.splitlines(): logSys.log(std_level, "%x -- stderr: %r", realCmdId, uni_decode(l)) - popen.stderr.close() + popen.stdout.close() + popen.stderr.close() success = False if retcode in success_codes: