From cc1865dc5b470753b2e7d2e730fedc4bed63e6ee Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 2 Jun 2021 15:35:46 -0400 Subject: [PATCH] island: Log a warning if MongoDbProcess.stop() is erroniously called --- .../cc/setup/mongo/mongo_db_process.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py b/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py index 925405ba5..0d517bf6d 100644 --- a/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py +++ b/monkey/monkey_island/cc/setup/mongo/mongo_db_process.py @@ -36,17 +36,21 @@ class MongoDbProcess: logger.info("MongoDB launched successfully!") def stop(self): - if self._process: - logger.info("Terminating MongoDB process") - self._process.terminate() - try: - self._process.wait(timeout=TERMINATE_TIMEOUT) - logger.info("MongoDB process terminated successfully") - except subprocess.TimeoutExpired as te: - logger.warning( - f"MongoDB did not terminate gracefully and will be forcefully killed: {te}" - ) - self._process.kill() + if not self._process: + logger.warning("Failed to stop MongoDB process: No process found") + return + + logger.info("Terminating MongoDB process") + self._process.terminate() + + try: + self._process.wait(timeout=TERMINATE_TIMEOUT) + logger.info("MongoDB process terminated successfully") + except subprocess.TimeoutExpired as te: + logger.warning( + f"MongoDB did not terminate gracefully and will be forcefully killed: {te}" + ) + self._process.kill() @staticmethod def _build_mongo_run_cmd(exec_path: str, db_dir: str) -> List[str]: