From ca8eb7e0760297c2bb8abc49fe58af57637de3fb Mon Sep 17 00:00:00 2001 From: Dmitry Kuzmenko Date: Fri, 9 Sep 2016 15:27:20 +0300 Subject: [PATCH 1/2] Don't run the same signal handler twice. Catch os.kill errors. Else a Process Not Found error stops the killing loop and there are still alive master subprocesses. --- salt/utils/process.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/salt/utils/process.py b/salt/utils/process.py index 20e74f635a3c..eefe8d377f80 100644 --- a/salt/utils/process.py +++ b/salt/utils/process.py @@ -409,6 +409,10 @@ def kill_children(self, *args, **kwargs): ''' Kill all of the children ''' + # first lets reset signal handlers to default one to prevent running this twice + signal.signal(signal.SIGTERM, signal.SIG_IGN) + signal.signal(signal.SIGINT, signal.SIG_IGN) + # check that this is the correct process, children inherit this # handler, if we are in a child lets just run the original handler if os.getpid() != self._pid: @@ -433,7 +437,10 @@ def kill_children(self, *args, **kwargs): log.trace('Terminating pid {0}: {1}'.format(pid, p_map['Process'])) if args: # escalate the signal to the process - os.kill(pid, args[0]) + try: + os.kill(pid, args[0]) + except OSError: + pass try: p_map['Process'].terminate() except OSError as exc: @@ -477,7 +484,7 @@ def kill_children(self, *args, **kwargs): continue log.trace('Killing pid {0}: {1}'.format(pid, p_map['Process'])) try: - os.kill(signal.SIGKILL, pid) + os.kill(pid, signal.SIGKILL) except OSError: # in case the process has since decided to die, os.kill returns OSError if not p_map['Process'].is_alive(): @@ -648,6 +655,8 @@ def __setup_signals(self): signal.signal(signal.SIGTERM, self._handle_signals) def _handle_signals(self, signum, sigframe): + signal.signal(signal.SIGTERM, signal.SIG_IGN) + signal.signal(signal.SIGINT, signal.SIG_IGN) msg = '{0} received a '.format(self.__class__.__name__) if signum == signal.SIGINT: msg += 'SIGINT' From 229504efef7e07453cf0fa1ff26f53008a343dae Mon Sep 17 00:00:00 2001 From: Dmitry Kuzmenko Date: Fri, 9 Sep 2016 15:29:03 +0300 Subject: [PATCH 2/2] Removed unused import. --- salt/log/handlers/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/log/handlers/__init__.py b/salt/log/handlers/__init__.py index 94bd3e22478b..1532d22c5662 100644 --- a/salt/log/handlers/__init__.py +++ b/salt/log/handlers/__init__.py @@ -11,7 +11,6 @@ # Import python libs import sys -import atexit import logging import threading import logging.handlers