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")