fix(gateway): make zombie check defensive against partial psutil stubs

The zombie status probe referenced psutil.Process/NoSuchProcess/Error
unconditionally, which raised AttributeError when psutil is a partial
stub that only defines pid_exists (as in test_windows_native_support's
fallback tests). Guard the probe so any failure to read status degrades
to the authoritative pid_exists() instead of raising.
This commit is contained in:
teknium1 2026-06-28 03:11:03 -07:00 committed by Teknium
parent acca526286
commit 9bb5a809b5

View file

@ -555,13 +555,16 @@ def _pid_exists(pid: int) -> bool:
# with exit 1 — a silent crash loop under systemd ``Restart=always``,
# which respawns the gateway before reaping the previous process
# (issue #42126). Report zombies as dead so the takeover proceeds.
# Best-effort: any failure to read status (partial/stub psutil,
# access denied, transient race) falls through to the authoritative
# ``pid_exists()`` below rather than raising.
try:
if psutil.Process(int(pid)).status() == psutil.STATUS_ZOMBIE:
return False
except psutil.NoSuchProcess:
except getattr(psutil, "NoSuchProcess", ()):
return False
except psutil.Error:
pass # Access denied / transient — defer to pid_exists below.
except Exception:
pass
return bool(psutil.pid_exists(int(pid)))
except ImportError: