Skip to content

fix: close /proc/cmdline file handles in PID scan loop#27910

Open
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/resource-leak-pid-scan
Open

fix: close /proc/cmdline file handles in PID scan loop#27910
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/resource-leak-pid-scan

Conversation

@vanthinh6886

Copy link
Copy Markdown
Contributor

Problem

_find_hermes_pids() in hermes_cli/gateway.py scans /proc/ to find running Hermes processes. For each PID, it opens /proc/{pid}/cmdline but never closes the file handle:

cmdline = open(f"/proc/{pid}/cmdline", "rb").read().decode("utf-8", errors="replace")

On a system with hundreds of processes, this leaks hundreds of file descriptors in a single call.

Fix

Use a with statement (context manager) to ensure each handle is closed immediately after reading:

with open(f"/proc/{pid}/cmdline", "rb") as fh:
    cmdline = fh.read().decode("utf-8", errors="replace")

Impact

  • Eliminates fd leak in a hot loop (called on every gateway startup and status check)
  • No behavioral change on the happy path

The previous code opened /proc/{pid}/cmdline without closing the file
handle. In a loop over all system PIDs, this leaks hundreds of file
descriptors. Use a context manager (with statement) to ensure each
handle is closed immediately after reading.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels May 18, 2026
@BoardJames-Bot

Copy link
Copy Markdown

Board James triage pass: this PR's check-attribution failure is the same missing-author-map issue as #27909/#27913: vanthinh6886@gmail.com (vanthinh6886) is not in scripts/release.py AUTHOR_MAP. I opened #27931 with the central fix ("vanthinh6886@gmail.com": "vanthinh6886"). The test job did not expose a branch-local assertion failure in logs; it was cancelled at ~95% progress. After #27931 lands, please rebase/rerun checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants