Skip to content

fix(gateway): close /proc cmdline file handle in PID scan loop - #28472

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/proc-fd-leak-gateway
Closed

fix(gateway): close /proc cmdline file handle in PID scan loop#28472
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/proc-fd-leak-gateway

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Problem

_find_gateway_pids_by_profile() in hermes_cli/gateway.py opens /proc/{pid}/cmdline for every numeric PID entry without closing the file handle. On busy systems with hundreds of PIDs, this leaks file descriptors.

Fix

Use a with statement for deterministic cleanup:

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

The /proc scanning loop opened /proc/{pid}/cmdline for every numeric
PID entry without closing the file handle. On busy systems with
hundreds of PIDs, this leaks file descriptors until GC runs.

Use a with-statement to ensure deterministic cleanup.

Signed-off-by: annguyenNous <annguyenNous@users.noreply.github.com>
@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 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27910 — both fix /proc/{pid}/cmdline file descriptor leak in the PID scan loop (bare open() without context manager). #27910 targets _find_hermes_pids(), this PR targets _find_gateway_pids_by_profile() in the same file. Same fix pattern (add with statement), introduced by #22860.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused resource-leak cleanup. An automated hermes-sweeper review found that this exact fix is already present on current main, so I’m closing this as implemented_on_main.

Evidence:

  • hermes_cli/gateway.py:455 now uses with open(f"/proc/{pid}/cmdline", "rb") as _f: and reads from that handle at hermes_cli/gateway.py:456, so the descriptor is closed immediately.
  • The implementing commit is d4b533de4edd2211125dfe3904959d1cd41c5642 (fix: batch of small robustness/correctness fixes from @kyssta-exe), whose commit message explicitly lists the gateway /proc/<pid>/cmdline fd-release fix.
  • git tag --contains d4b533de4 shows the fix is contained in v2026.6.5.

The prior duplicate note linking this to the same leak pattern as #27910 was useful context; the current main code now covers this PR’s requested behavior.

@teknium1 teknium1 closed this Jun 15, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 15, 2026
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 sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants