Description
On Windows, when a stale gateway.pid file exists (e.g. after a non-graceful shutdown), restarting the gateway fails because os.kill(existing_pid, 0) raises OSError: [WinError 11] instead of ProcessLookupError.
Location
gateway/status.py, around line 364:
try:
os.kill(existing_pid, 0)
except (ProcessLookupError, PermissionError):
stale = True
Problem
On Windows, when the PID no longer exists, os.kill can raise a generic OSError (e.g. [WinError 11]), which is not caught by the current handler. This causes the gateway to fail to start until the PID file is manually deleted.
This issue recurs every time the gateway exits non-gracefully (closing terminal, system crash, unhandled Ctrl+C, etc.).
Suggested Fix
Add OSError to the exception tuple:
except (ProcessLookupError, PermissionError, OSError):
stale = True
Note: ProcessLookupError is already a subclass of OSError, so this is a safe superset. If that feels too broad, an alternative is to check sys.platform == "win32" or catch OSError and filter by errno.
Environment
- OS: Windows 10/11
- Python: 3.x (venv)
- Hermes Gateway: latest
Description
On Windows, when a stale
gateway.pidfile exists (e.g. after a non-graceful shutdown), restarting the gateway fails becauseos.kill(existing_pid, 0)raisesOSError: [WinError 11]instead ofProcessLookupError.Location
gateway/status.py, around line 364:Problem
On Windows, when the PID no longer exists,
os.killcan raise a genericOSError(e.g.[WinError 11]), which is not caught by the current handler. This causes the gateway to fail to start until the PID file is manually deleted.This issue recurs every time the gateway exits non-gracefully (closing terminal, system crash, unhandled Ctrl+C, etc.).
Suggested Fix
Add
OSErrorto the exception tuple:Note:
ProcessLookupErroris already a subclass ofOSError, so this is a safe superset. If that feels too broad, an alternative is to checksys.platform == "win32"or catchOSErrorand filter byerrno.Environment