mirror of https://github.com/fail2ban/fail2ban
proper stop server in the test cases (quit should stop all server-side threads, also if server was not really started);
fix-up for run_with_except_hook: avoid very sporadic error "'NoneType' object has no attribute 'exc_info'" (https://bugs.python.org/issue7336), only extremely fast systems are affected ATM (2.x / 3.x), if thread ends nothing is available in .pull/1995/head
parent
2712f72650
commit
aa9cefc3f8
|
@ -67,8 +67,13 @@ class JailThread(Thread):
|
||||||
def run_with_except_hook(*args, **kwargs):
|
def run_with_except_hook(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
run(*args, **kwargs)
|
run(*args, **kwargs)
|
||||||
except:
|
except Exception as e:
|
||||||
excepthook(*sys.exc_info())
|
# avoid very sporadic error "'NoneType' object has no attribute 'exc_info'" (https://bugs.python.org/issue7336)
|
||||||
|
# only extremely fast systems are affected ATM (2.7 / 3.x), if thread ends nothing is available here.
|
||||||
|
if sys is not None:
|
||||||
|
excepthook(*sys.exc_info())
|
||||||
|
else:
|
||||||
|
print(e)
|
||||||
self.run = run_with_except_hook
|
self.run = run_with_except_hook
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
|
@ -82,7 +82,7 @@ class Server:
|
||||||
|
|
||||||
def __sigTERMhandler(self, signum, frame): # pragma: no cover - indirect tested
|
def __sigTERMhandler(self, signum, frame): # pragma: no cover - indirect tested
|
||||||
logSys.debug("Caught signal %d. Exiting", signum)
|
logSys.debug("Caught signal %d. Exiting", signum)
|
||||||
self.quit()
|
self.quit_signal()
|
||||||
|
|
||||||
def __sigUSR1handler(self, signum, fname): # pragma: no cover - indirect tested
|
def __sigUSR1handler(self, signum, fname): # pragma: no cover - indirect tested
|
||||||
logSys.debug("Caught signal %d. Flushing logs", signum)
|
logSys.debug("Caught signal %d. Flushing logs", signum)
|
||||||
|
@ -152,6 +152,20 @@ class Server:
|
||||||
except AsyncServerException as e:
|
except AsyncServerException as e:
|
||||||
logSys.error("Could not start server: %s", e)
|
logSys.error("Could not start server: %s", e)
|
||||||
|
|
||||||
|
# Stop server
|
||||||
|
self.quit()
|
||||||
|
|
||||||
|
# Removes the PID file.
|
||||||
|
try:
|
||||||
|
logSys.debug("Remove PID file %s", pidfile)
|
||||||
|
os.remove(pidfile)
|
||||||
|
except (OSError, IOError) as e: # pragma: no cover
|
||||||
|
logSys.error("Unable to remove PID file: %s", e)
|
||||||
|
logSys.info("Exiting Fail2ban")
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
self.quit_signal()
|
||||||
|
|
||||||
logSys.info("Shutdown in progress...")
|
logSys.info("Shutdown in progress...")
|
||||||
|
|
||||||
# Restore default signal handlers:
|
# Restore default signal handlers:
|
||||||
|
@ -168,17 +182,9 @@ class Server:
|
||||||
self.__db.close()
|
self.__db.close()
|
||||||
self.__db = None
|
self.__db = None
|
||||||
|
|
||||||
# Removes the PID file.
|
def quit_signal(self):
|
||||||
try:
|
# Prevent to call quit_signal twice:
|
||||||
logSys.debug("Remove PID file %s", pidfile)
|
self.quit_signal = lambda: False
|
||||||
os.remove(pidfile)
|
|
||||||
except (OSError, IOError) as e: # pragma: no cover
|
|
||||||
logSys.error("Unable to remove PID file: %s", e)
|
|
||||||
logSys.info("Exiting Fail2ban")
|
|
||||||
|
|
||||||
def quit(self):
|
|
||||||
# Prevent to call quit twice:
|
|
||||||
self.quit = lambda: False
|
|
||||||
# Stop communication first because if jail's unban action
|
# Stop communication first because if jail's unban action
|
||||||
# tries to communicate via fail2ban-client we get a lockup
|
# tries to communicate via fail2ban-client we get a lockup
|
||||||
# among threads. So the simplest resolution is to stop all
|
# among threads. So the simplest resolution is to stop all
|
||||||
|
|
Loading…
Reference in New Issue