From b50e39df578adc3f86c5efa16bee9035cfdab61b Mon Sep 17 00:00:00 2001 From: Sean Quah <8349537+squahtx@users.noreply.github.com> Date: Thu, 2 Dec 2021 16:07:06 +0000 Subject: [PATCH] Avoid waiting for zombie processes in `synctl stop` (#11490) --- changelog.d/11490.feature | 1 + synctl | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 changelog.d/11490.feature diff --git a/changelog.d/11490.feature b/changelog.d/11490.feature new file mode 100644 index 0000000000..4cb97dc1d0 --- /dev/null +++ b/changelog.d/11490.feature @@ -0,0 +1 @@ +`synctl stop` will now wait for Synapse to exit before returning. diff --git a/synctl b/synctl index 08709f21ab..0e54f4847b 100755 --- a/synctl +++ b/synctl @@ -41,11 +41,24 @@ NORMAL = "\x1b[m" def pid_running(pid): try: os.kill(pid, 0) - return True except OSError as err: if err.errno == errno.EPERM: - return True - return False + pass # process exists + else: + return False + + # When running in a container, orphan processes may not get reaped and their + # PIDs may remain valid. Try to work around the issue. + try: + with open(f"/proc/{pid}/status") as status_file: + if "zombie" in status_file.read(): + return False + except Exception: + # This isn't Linux or `/proc/` is unavailable. + # Assume that the process is still running. + pass + + return True def write(message, colour=NORMAL, stream=sys.stdout):