From b15705852e5fd61659e0152bd4706a30c697246c Mon Sep 17 00:00:00 2001 From: elhoim Date: Mon, 31 Aug 2026 01:05:06 +0000 Subject: [PATCH] fix: [__init__] catch NoSuchProcess/ZombieProcess in get_misp_modules_pid get_misp_modules_pid() scans all live pids and inspects each process's cmdline to find a running misp-modules instance, catching only psutil.AccessDenied. Between psutil.pids() enumerating a pid and Process(pid).cmdline() being called, that process can exit, which raises psutil.NoSuchProcess (or ZombieProcess for a process stuck in the zombie state); neither is caught, so the exception propagates out of the function. This is invoked from the "address already in use" diagnostic in __main__.py, so a process exiting mid-scan crashes that diagnostic and hides the real bind error the user needed to see. Verified with flake8 on the changed file (clean) and the full pytest suite against a live server on port 6774: 161 passed, 4 skipped, 5 subtests passed, matching the recorded baseline. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8 --- misp_modules/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misp_modules/__init__.py b/misp_modules/__init__.py index df6fe1ba..e0646b29 100644 --- a/misp_modules/__init__.py +++ b/misp_modules/__init__.py @@ -103,7 +103,7 @@ def get_misp_modules_pid() -> typing.Union[int, None]: if any("misp-modules" in x for x in psutil.Process(pid).cmdline()): return pid return None - except psutil.AccessDenied: + except (psutil.AccessDenied, psutil.NoSuchProcess, psutil.ZombieProcess): return None