From 3f7c4a8859b1d71cab4982f49489c8b06d309d50 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 24 Nov 2021 10:40:05 +0200 Subject: [PATCH] Agent: add a comment warning that windows will terminate the process 5s after CTRL_CLOSE_EVENT signal The comment will warn us that in case that particular signal is raised, the cleanup shouldn't take longer than 5s --- monkey/infection_monkey/utils/signal_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/utils/signal_handler.py b/monkey/infection_monkey/utils/signal_handler.py index a2f865ce2..d75b08f10 100644 --- a/monkey/infection_monkey/utils/signal_handler.py +++ b/monkey/infection_monkey/utils/signal_handler.py @@ -12,7 +12,7 @@ class StopSignalHandler: def __init__(self, master: IMaster): self._master = master - def __call__(self, signum, __=None): + def __call__(self, signum, _=None): logger.info(f"The Monkey Agent received signal {signum}") self._master.terminate() raise PlannedShutdownException("Monkey Agent got an interrupt signal") @@ -27,4 +27,7 @@ def register_signal_handlers(master: IMaster): import win32api signal.signal(signal.SIGBREAK, stop_signal_handler) + + # CTRL_CLOSE_EVENT signal has a timeout of 5000ms, + # after that OS will forcefully kill the process win32api.SetConsoleCtrlHandler(stop_signal_handler, True)