Merge PR #568: fix(code-execution): close server socket in finally block to prevent fd leak
Authored by alireza78a. Moves server_sock.close() into the finally block so the socket fd is always cleaned up, even if an exception occurs between socket creation and the success-path close.
This commit is contained in:
commit
ab6a6338c4
1 changed files with 4 additions and 1 deletions
|
|
@ -511,7 +511,6 @@ def execute_code(
|
||||||
duration = round(time.monotonic() - exec_start, 2)
|
duration = round(time.monotonic() - exec_start, 2)
|
||||||
|
|
||||||
# Wait for RPC thread to finish
|
# Wait for RPC thread to finish
|
||||||
server_sock.close()
|
|
||||||
rpc_thread.join(timeout=3)
|
rpc_thread.join(timeout=3)
|
||||||
|
|
||||||
# Build response
|
# Build response
|
||||||
|
|
@ -547,6 +546,10 @@ def execute_code(
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Cleanup temp dir and socket
|
# Cleanup temp dir and socket
|
||||||
|
try:
|
||||||
|
server_sock.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
import shutil
|
import shutil
|
||||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue