From 9255bf954a0c5ce0afb9553b3b21352bc00148a6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 6 Oct 2025 13:28:46 -0500 Subject: [PATCH] Revert "PYTHON-5594 Make process shutdown more robust (#322)" This reverts commit 570a56f55c60f8309ff9f363743020365c700b8f. --- mongo_orchestration/daemon.py | 10 ++-------- tests/test_launch.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mongo_orchestration/daemon.py b/mongo_orchestration/daemon.py index 5104afc..bf3983c 100644 --- a/mongo_orchestration/daemon.py +++ b/mongo_orchestration/daemon.py @@ -22,7 +22,7 @@ import sys import time -from signal import SIGTERM, SIGKILL +from signal import SIGTERM DEVNULL = open(os.devnull, 'r+b') @@ -174,15 +174,8 @@ def stop(self): # Try killing the daemon process try: os.kill(pid, SIGTERM) - t0 = time.time() while is_unix_process_running(pid): time.sleep(0.25) - # After 5 seconds resend a SIGTERM to the process. - if time.time() - t0 > 5: - os.kill(pid, SIGTERM) - # After 10 seconds send a SIGKILL to the process. - if time.time() - t0 > 10: - os.kill(pid, SIGKILL) except OSError as err: if err.errno == errno.ESRCH: if os.path.exists(self.pidfile): @@ -216,3 +209,4 @@ def is_unix_process_running(pid): else: raise err return True + diff --git a/tests/test_launch.py b/tests/test_launch.py index df11d8b..95354a9 100644 --- a/tests/test_launch.py +++ b/tests/test_launch.py @@ -26,6 +26,12 @@ def run(cmd, **kwargs): if proc.returncode != 0: raise RuntimeError('Process failed!') + +def stop(): + pid = Path("server.pid").read_text().strip() + os.kill(int(pid), signal.SIGTERM) + Path("server.pid").unlink() + class TestLaunch(unittest.TestCase): def test_launch_single(self): @@ -37,7 +43,9 @@ def test_launch_single(self): proc.send('q\n') proc.wait() self.assertEqual(proc.exitstatus, 0) - run('mongo-orchestration stop') + # TODO: https://jira.mongodb.org/browse/PYTHON-5594 + # run('mongo-orchestration stop') + stop() def test_launch_replica_set(self): if os.name != 'posix': @@ -48,7 +56,9 @@ def test_launch_replica_set(self): proc.send('q\n') proc.wait() self.assertEqual(proc.exitstatus, 0) - run('mongo-orchestration stop') + # TODO: https://jira.mongodb.org/browse/PYTHON-5594 + # run('mongo-orchestration stop') + stop() def test_launch_sharded(self): @@ -60,4 +70,6 @@ def test_launch_sharded(self): proc.send('q\n') proc.wait() self.assertEqual(proc.exitstatus, 0) - run('mongo-orchestration stop') + # TODO: https://jira.mongodb.org/browse/PYTHON-5594 + # run('mongo-orchestration stop') + stop()