Skip to content

[Core] Fix resource leaks in subprocess management#63878

Merged
edoakes merged 2 commits into
ray-project:masterfrom
Accurio:resource-leak
Jun 8, 2026
Merged

[Core] Fix resource leaks in subprocess management#63878
edoakes merged 2 commits into
ray-project:masterfrom
Accurio:resource-leak

Conversation

@Accurio

@Accurio Accurio commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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 #9546, Fixes #59782

@Accurio Accurio requested a review from a team as a code owner June 5, 2026 10:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/ray/_private/node.py Outdated
Comment thread python/ray/_private/node.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 50d323d. Configure here.

Comment thread python/ray/_private/services.py
- 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>
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jun 5, 2026
@edoakes edoakes added the go add ONLY when ready to merge, run all tests label Jun 5, 2026
Comment thread python/ray/_private/node.py Outdated
Signed-off-by: Accurio <2671768169@qq.com>
@Accurio Accurio requested a review from edoakes June 8, 2026 09:18
@edoakes edoakes merged commit dbc1523 into ray-project:master Jun 8, 2026
6 checks passed
@Accurio Accurio deleted the resource-leak branch June 9, 2026 04:55
sampan-s-nayak pushed a commit to sampan-s-nayak/ray that referenced this pull request Jun 10, 2026
## 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>
limarkdcunha pushed a commit to limarkdcunha/ray that referenced this pull request Jun 30, 2026
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

2 participants