Fix resource leak and double socket close in tools

NousResearch/hermes-agent · cluster 2136 · agent

Data as of

Nothing open on GitHub. Fix merged in #2381. Check it covers your case.

The short answer

0open issues
0open PRs
5items grouped
Known?
Yes. 5 related items grouped here, 1 issue already closed.
Fix event
A fix was merged to main in PR #2381. Check it covers your case. No release data is tracked.
Tracker
The maintainers' tracker marks this resolved, deciding PR #2381. That is separate from the fix event.
Still open
Nothing open on GitHub.

These entries all address the same issue: a resource leak and double socket close bug in the code execution tool. The members appear to be duplicates or near-duplicates of the same fix.

Open issues0

No open issues.

Open PRs0

No open pull requests.

Fixes on record

Merged to main. A stamp counts the issues a fix is linked to.

  • #2381 fix(tools): resource leak and double socket close in code_execution_tool

    merged to main

    files: tools/code_execution_tool.py

    Show the diff
    • tools/code_execution_tool.py
      @@ -300,16 +300,16 @@ def _rpc_server_loop(
                       # their status prints don't leak into the CLI spinner.
                       try:
                           _real_stdout, _real_stderr = sys.stdout, sys.stderr
      -                    sys.stdout = open(os.devnull, "w")
      -                    sys.stderr = open(os.devnull, "w")
      +                    devnull = open(os.devnull, "w")
                           try:
      +                        sys.stdout = devnull
      +                        sys.stderr = devnull
                               result = handle_function_call(
                                   tool_name, tool_args, task_id=task_id
                               )
                           finally:
      -                        sys.stdout.close()
      -                        sys.stderr.close()
                               sys.stdout, sys.stderr = _real_stdout, _real_stderr
      +                        devnull.close()
                       except Exception as exc:
                           logger.error("Tool call failed in sandbox: %s", exc, exc_info=True)
                           result = json.dumps({"error": str(exc)})
      @@ -574,6 +574,7 @@ def _drain_head_tail(pipe, head_chunks, tail_chunks, head_bytes, tail_bytes, tot
       
               # Wait for RPC thread to finish
               server_sock.close()  # break accept() so thread exits promptly
      +        server_sock = None  # prevent double close in finally
               rpc_thread.join(timeout=3)
       
               # Build response

3 PRs closed without merging

From the close comments: merged via another change 2 · done elsewhere 1

  • #2140 fix(tools): resource leak and double socket close in code_execution_tool · merged via another change → #2381, #2250
  • #2250 fix(tools): fix resource leak and double socket close in code_execution_tool · merged via another change → #2381
  • #2291 fix(tools): resource leak and double socket close in code_execution_tool · done elsewhere
Closed issues · 1
  • Closed#2136fix(tools): resource leak and double socket close in code_execution_tool
How this cluster was grouped
  • Link evidence (structural links throughout): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
  • Pairwise link density 0.40: the share of item pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. 1.00 means every pair is linked.

Pick up a Lab task

Check whether a fix covers the open issues here, with your own agent. Bring back evidence for maintainers.

Open the Lab

At a glance

Subsystem
agent
Merged PRs
#2381
Closed issues
1
Attempts
3 PRs closed without merging
Fix link checked
21 Mar 2026. This confirmation is old and may be out of date (a revert or reopen would not have invalidated it here); re-verify.

For your agent

The same facts, typed.