From cdb66072610aee2b621e7c5f79280e0c93f1e0df Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 22 Nov 2023 20:00:50 +0100 Subject: [PATCH 1/3] remove double call of inherited setup in test cases; previously caused that after that no restore of log-handler takes place in `tearDown` later, so after that tests it remains by `LogCaptureTestCase._MemHandler`, so every future logged message disappear in nirvana; partially fixes #3635 --- fail2ban/tests/sockettestcase.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fail2ban/tests/sockettestcase.py b/fail2ban/tests/sockettestcase.py index 4eb3a375..5c674620 100644 --- a/fail2ban/tests/sockettestcase.py +++ b/fail2ban/tests/sockettestcase.py @@ -54,7 +54,6 @@ class Socket(LogCaptureTestCase): def setUp(self): """Call before every test case.""" - LogCaptureTestCase.setUp(self) super(Socket, self).setUp() self.server = AsyncServer(self) sock_fd, sock_name = tempfile.mkstemp('fail2ban.sock', 'f2b-socket') @@ -68,7 +67,7 @@ class Socket(LogCaptureTestCase): if self.serverThread: self.server.stop(); # stop if not already stopped self._stopServerThread() - LogCaptureTestCase.tearDown(self) + super(Socket, self).tearDown() @staticmethod def proceed(message): From 4d603f97261f879b56f55460cadd84a06844ca93 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 22 Nov 2023 20:01:31 +0100 Subject: [PATCH 2/3] added missing inherited `tearDown` invocation --- fail2ban/tests/clientreadertestcase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 1baff568..0388fd3d 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -61,6 +61,7 @@ class ConfigReaderTest(unittest.TestCase): def tearDown(self): """Call after every test case.""" shutil.rmtree(self.d) + super(ConfigReaderTest, self).tearDown() def _write(self, fname, value=None, content=None): # verify if we don't need to create .d directory From 5d9817728da9a7355b02b5966dffd51a0441462e Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 22 Nov 2023 20:05:02 +0100 Subject: [PATCH 3/3] fixes multi-threaded issue on `__pending` dict (caused due to missing lock on `__pending` dict); an entry can be deleted by `_delPending` with 1st thread, while 2nd thread in filter doing `_checkPending` where it still got this key in iterator, but later fails in the cycle because `__pending[path]` may be deleted by 1st thread in-between; closes #3635 --- fail2ban/server/filterpyinotify.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fail2ban/server/filterpyinotify.py b/fail2ban/server/filterpyinotify.py index 2ee49169..81bc7de3 100644 --- a/fail2ban/server/filterpyinotify.py +++ b/fail2ban/server/filterpyinotify.py @@ -173,7 +173,9 @@ class FilterPyinotify(FileFilter): if not chkpath(path): # not found - prolong for next time if retardTM < 60: retardTM *= 2 if minTime > retardTM: minTime = retardTM - self.__pending[path][0] = retardTM + try: + self.__pending[path][0] = retardTM + except KeyError: pass continue logSys.log(logging.MSG, "Log presence detected for %s %s", "directory" if isDir else "file", path)