Repository navigation
[core] Ensure we free objects whose location report arrives after the ref got dropped - #66383
Conversation
…ject was freed Signed-off-by: yicheng <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where object copies could be leaked if a location report arrives after the reference has already been dropped. It introduces an asynchronous free of the object on nodes when the reference does not exist in CoreWorker::AddObjectLocationOwner, and adds a corresponding unit test. However, a review comment identifies a potential memory leak under a specific race condition where maybe_generator_id is not Nil() but the reference does not exist, causing the code to skip the newly added else if block. It is recommended to update reference_exists with the result of AddObjectLocation and perform the !reference_exists check unconditionally after the block.
…t-after-drop order Signed-off-by: yicheng <[email protected]>
Signed-off-by: yicheng <[email protected]>
| } | ||
| if (!reference_counter_->AddObjectLocation(object_id, node_id)) { | ||
| // The ref may be dropped and free objects sent before this report arrives, so free | ||
| // the additional objects here. |
There was a problem hiding this comment.
nit: "free the additional objects here" -> "free the additional copies here"
Signed-off-by: yicheng <[email protected]>
## Why are these changes needed? Since about 2026-09-23 04:45 UTC, Read the Docs builds on `anyscale-ray` have been intermittently dying with a bare segfault in `sphinx-build`: ``` [autosummary] generating autosummary for: 404.md, ... make: *** [Makefile:100: html] Segmentation fault (core dumped) ``` What I found in the build history: - None of the 132 finished builds from 2026-09-18 up to the onset segfaulted. There have been 23 since, on both `master` and PR previews across at least 10 PRs. In one 13-hour window, 10 of 32 finished builds crashed. - Every crash is at the same point, about 6 to 7 seconds into the `make html` step, right after autosummary starts. This isn't the memory-limit failure that the `SPHINX_JOBS=2` comment describes, which surfaces as an `EOFError` from a worker much later in the build. - It isn't deterministic per commit. `master` at 8a94f8b segfaulted in builds 4473269 and 4474033, then passed in 4474041. A line-by-line diff of the failing and passing logs shows the same commands, the same Python (3.11.15), and the same installed package versions. - No doc-build input changed in the onset window. The only commit that landed on `master` in it was a core C++ change (#66383), which the docs build doesn't compile. That points to a change in the build environment rather than in this repo, but the log gives nothing to hand to Read the Docs support or to act on. This PR sets `PYTHONFAULTHANDLER=1` on the html build step so the next crash dumps the Python stack of every thread to stderr. That should name the module or C extension that crashed. The handler only does anything when a fatal signal arrives, so passing builds are unaffected. Once the cause is found and fixed, this can stay as cheap insurance or be reverted. ## Related issue number None. I searched open and closed PRs for `faulthandler`, `readthedocs segfault`, and `Segmentation fault`, and none of them cover the docs build. #66364 fixes a segfault on `import ray` when a `RAY_*` env var is malformed, which is a different path in core's static initialization. ## Testing - Ran a deliberately segfaulting Python child through a `make` recipe, the same way the build invokes `sphinx-build`. With `PYTHONFAULTHANDLER=1`, make's output includes `Fatal Python error: Segmentation fault` and the Python traceback. Without it, the output is only make's `Segmentation fault` line. - `python3 -c "import yaml; yaml.safe_load(open('.readthedocs.yaml'))"` parses, and the html build command reads back as expected. - `pre-commit run --files .readthedocs.yaml` passes. - The Read the Docs preview for this PR runs the modified step, because the preview guard builds whenever `.readthedocs.yaml` changes. ## AI assistance I used Claude Code to survey the Read the Docs build history through the RtD API, diff the build logs, and draft this change. I reviewed the diff and the evidence above. ## Checks - [x] I've signed off every commit (by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run pre-commit jobs to lint the changes in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
… ref got dropped (ray-project#66383) ## Description We had a race condition that caused objects to not get freed: - owner call `ray.get` - raylet finishes pulling object and reports the new location to the owner. Assume this report remains in flight. - owner finds the object, finishes `ray.get`, and then drops the ref immediately, triggering object freeing. The owner only sends `FreeLocalObjects` to the locations it has recorded at that moment. raylet's report hasn't arrived yet. - When the report arrives, the owner no longer has an entry for that object and discards it. The fix is simple. we send `FreeLocalObjects` if there is no object entry in the owner. --------- Signed-off-by: yicheng <[email protected]> Co-authored-by: yicheng <[email protected]>
…ject#66452) ## Why are these changes needed? Since about 2026-09-23 04:45 UTC, Read the Docs builds on `anyscale-ray` have been intermittently dying with a bare segfault in `sphinx-build`: ``` [autosummary] generating autosummary for: 404.md, ... make: *** [Makefile:100: html] Segmentation fault (core dumped) ``` What I found in the build history: - None of the 132 finished builds from 2026-09-18 up to the onset segfaulted. There have been 23 since, on both `master` and PR previews across at least 10 PRs. In one 13-hour window, 10 of 32 finished builds crashed. - Every crash is at the same point, about 6 to 7 seconds into the `make html` step, right after autosummary starts. This isn't the memory-limit failure that the `SPHINX_JOBS=2` comment describes, which surfaces as an `EOFError` from a worker much later in the build. - It isn't deterministic per commit. `master` at 8a94f8b segfaulted in builds 4473269 and 4474033, then passed in 4474041. A line-by-line diff of the failing and passing logs shows the same commands, the same Python (3.11.15), and the same installed package versions. - No doc-build input changed in the onset window. The only commit that landed on `master` in it was a core C++ change (ray-project#66383), which the docs build doesn't compile. That points to a change in the build environment rather than in this repo, but the log gives nothing to hand to Read the Docs support or to act on. This PR sets `PYTHONFAULTHANDLER=1` on the html build step so the next crash dumps the Python stack of every thread to stderr. That should name the module or C extension that crashed. The handler only does anything when a fatal signal arrives, so passing builds are unaffected. Once the cause is found and fixed, this can stay as cheap insurance or be reverted. ## Related issue number None. I searched open and closed PRs for `faulthandler`, `readthedocs segfault`, and `Segmentation fault`, and none of them cover the docs build. ray-project#66364 fixes a segfault on `import ray` when a `RAY_*` env var is malformed, which is a different path in core's static initialization. ## Testing - Ran a deliberately segfaulting Python child through a `make` recipe, the same way the build invokes `sphinx-build`. With `PYTHONFAULTHANDLER=1`, make's output includes `Fatal Python error: Segmentation fault` and the Python traceback. Without it, the output is only make's `Segmentation fault` line. - `python3 -c "import yaml; yaml.safe_load(open('.readthedocs.yaml'))"` parses, and the html build command reads back as expected. - `pre-commit run --files .readthedocs.yaml` passes. - The Read the Docs preview for this PR runs the modified step, because the preview guard builds whenever `.readthedocs.yaml` changes. ## AI assistance I used Claude Code to survey the Read the Docs build history through the RtD API, diff the build logs, and draft this change. I reviewed the diff and the evidence above. ## Checks - [x] I've signed off every commit (by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run pre-commit jobs to lint the changes in this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Description
We had a race condition that caused objects to not get freed:
ray.getray.get, and then drops the ref immediately, triggering object freeing. The owner only sendsFreeLocalObjectsto the locations it has recorded at that moment. raylet's report hasn't arrived yet.The fix is simple. we send
FreeLocalObjectsif there is no object entry in the owner.