[Core] Fix resource leaks in subprocess management#63878
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors process termination and I/O redirection in Ray. In services.py, manual file handles for os.devnull are replaced with subprocess.DEVNULL. In node.py, the process termination logic is modified to adjust wait timeouts. However, the feedback highlights two critical issues in node.py: first, setting the graceful termination timeout to None when wait is enabled can block indefinitely and prevent the force-kill fallback; second, unconditionally calling process.wait() after a force-kill when wait is disabled risks hanging on unkillable processes. It is recommended to use short timeouts in both cases to prevent indefinite blocking.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 50d323d. Configure here.
- In five start functions in services.py, replace `open(os.devnull)` with `subprocess.DEVNULL` to eliminate unclosed file handle warnings. - In `_kill_process_impl`, always call wait() after kill() to prevent zombie processes and eliminate still running subprocess warnings. Fixes ray-project#9546, Fixes ray-project#59782 Signed-off-by: Accurio <2671768169@qq.com>
Signed-off-by: Accurio <2671768169@qq.com>
## Description - Five startup methods in services.py create output handlers using `open(os.devnull, "w")` but never close, causing `ResourceWarning: unclosed file` warnings. Replaced with `subprocess.DEVNULL`. - Kill process method in Node do not call `wait()` after `kill()` when the argument `wait` is False, causing `ResourceWarning: subprocess is still running` warnings. Change to call `wait()` after `kill()` to prevent zombie processes. ## Related issues Fixes ray-project#9546, Fixes ray-project#59782 --------- Signed-off-by: Accurio <2671768169@qq.com>
## Description - Five startup methods in services.py create output handlers using `open(os.devnull, "w")` but never close, causing `ResourceWarning: unclosed file` warnings. Replaced with `subprocess.DEVNULL`. - Kill process method in Node do not call `wait()` after `kill()` when the argument `wait` is False, causing `ResourceWarning: subprocess is still running` warnings. Change to call `wait()` after `kill()` to prevent zombie processes. ## Related issues Fixes ray-project#9546, Fixes ray-project#59782 --------- Signed-off-by: Accurio <2671768169@qq.com>

Description
open(os.devnull, "w")but never close, causingResourceWarning: unclosed filewarnings. Replaced withsubprocess.DEVNULL.wait()afterkill()when the argumentwaitis False, causingResourceWarning: subprocess is still runningwarnings. Change to callwait()afterkill()to prevent zombie processes.Related issues
Fixes #9546, Fixes #59782