From 1d58ce36e7ee84f78d30569ba2469b6884c34a70 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 7 Sep 2022 19:45:12 -0400 Subject: [PATCH] Agent: Use a finally clause to ensure singleton is always unlocked --- monkey/infection_monkey/monkey.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 311ccd9c0..b242ad7d2 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -415,11 +415,12 @@ class InfectionMonkey: ).send() # Signal the server (before closing the tunnel) self._close_tunnel() - self._singleton.unlock() except Exception as e: logger.error(f"An error occurred while cleaning up the monkey agent: {e}") if deleted is None: InfectionMonkey._self_delete() + finally: + self._singleton.unlock() logger.info("Monkey is shutting down")