From e6f3326731ca2947e69d89394861b6cc8f831eed Mon Sep 17 00:00:00 2001 From: annguyenNous Date: Tue, 19 May 2026 11:34:09 +0700 Subject: [PATCH] fix(gateway): close /proc cmdline file handle in PID scan loop 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 --- hermes_cli/gateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index ef57d5ce9fec8..3ed41e616aa12 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -409,7 +409,8 @@ def _matches_current_profile(command: str) -> bool: if pid == my_pid or pid in exclude_pids: continue try: - cmdline = open(f"/proc/{pid}/cmdline", "rb").read().decode("utf-8", errors="replace") + with open(f"/proc/{pid}/cmdline", "rb") as fh: + cmdline = fh.read().decode("utf-8", errors="replace") cmdline = cmdline.replace("\x00", " ") if any(p in cmdline for p in patterns) and ( all_profiles or _matches_current_profile(cmdline)