fix: catch NoSuchProcess/ZombieProcess in get_misp_modules_pid - #883
Open
elhoim wants to merge 1 commit into
Open
fix: catch NoSuchProcess/ZombieProcess in get_misp_modules_pid#883elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
…_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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_misp_modules_pid()inmisp_modules/__init__.pyonly widens its exception handling topsutil.AccessDenied:psutil.pids()returns a snapshot; a process can exit between that enumeration and theProcess(pid).cmdline()call. When that happens, psutil raisespsutil.NoSuchProcess(orpsutil.ZombieProcessfor a process that has already exited but not been reaped), neither of which is caught here. The exception propagates out ofget_misp_modules_pid().This function is called from the "address already in use" diagnostic in
__main__.pywhen the server fails to bind its port, to report which PID is already holding it. If the race hits, the diagnostic itself crashes with an unrelatedpsutil.NoSuchProcesstraceback instead of reporting the real bind error, which is confusing for anyone debugging whymisp-moduleswon't start.Fix
Widen the except clause to
(psutil.AccessDenied, psutil.NoSuchProcess, psutil.ZombieProcess)so a process that exits mid-scan is treated the same as one we can't inspect: returnNoneand let the real "address already in use" message surface.This is a pure exception-handling fix with no behaviour change to the success path.
Verification
flake8clean onmisp_modules/__init__.pyFound during a review of the repository; other findings are being submitted as separate PRs.
🤖 Generated with Claude Code
https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8