Skip to content
Snippets Groups Projects
Unverified Commit b50e39df authored by Sean Quah's avatar Sean Quah Committed by GitHub
Browse files

Avoid waiting for zombie processes in `synctl stop` (#11490)

parent 858d80bf
No related branches found
No related tags found
No related merge requests found
`synctl stop` will now wait for Synapse to exit before returning.
...@@ -41,11 +41,24 @@ NORMAL = "\x1b[m" ...@@ -41,11 +41,24 @@ NORMAL = "\x1b[m"
def pid_running(pid): def pid_running(pid):
try: try:
os.kill(pid, 0) os.kill(pid, 0)
return True
except OSError as err: except OSError as err:
if err.errno == errno.EPERM: if err.errno == errno.EPERM:
return True pass # process exists
return False 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): def write(message, colour=NORMAL, stream=sys.stdout):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment