From a857321463ce6181e40bbcc266f321cc8dda5006 Mon Sep 17 00:00:00 2001 From: alireza78a Date: Sat, 7 Mar 2026 05:41:11 +0330 Subject: [PATCH] fix(code-execution): close server socket in finally block to prevent fd leak --- tools/code_execution_tool.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/code_execution_tool.py b/tools/code_execution_tool.py index a9e9d8081..13b2a7b27 100644 --- a/tools/code_execution_tool.py +++ b/tools/code_execution_tool.py @@ -502,7 +502,6 @@ def execute_code( duration = round(time.monotonic() - exec_start, 2) # Wait for RPC thread to finish - server_sock.close() rpc_thread.join(timeout=3) # Build response @@ -538,6 +537,10 @@ def execute_code( finally: # Cleanup temp dir and socket + try: + server_sock.close() + except Exception: + pass try: import shutil shutil.rmtree(tmpdir, ignore_errors=True)