Repository navigation
Conversation
`asio_chaos.cc` constructed its `DelayManager` in a static initializer, and that constructor reads `RayConfig::instance()`. When any `RAY_*` config env var fails to parse, the `RAY_CHECK` in `ConvertValue` tries to log before the `RayLog` statics are initialized, and the process segfaults while loading `_raylet.so`, i.e. on `import ray`. Construct the `DelayManager` lazily on first use instead, so `RayConfig` is first touched after static initialization. A malformed value now fails with the intended `Cannot parse "..." to <type>` check failure. Add a subprocess regression test that imports ray with a malformed `RAY_memory_monitor_refresh_ms` and asserts a clean failure instead of a SIGSEGV. Closes ray-project#49222 Signed-off-by: RunguoLi <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request prevents a crash during import ray when a malformed RAY_* environment variable is present. The fix lazily constructs the DelayManager in src/ray/asio/asio_chaos.cc to avoid accessing RayConfig during static initialization. A regression test is also added to verify this behavior. The review feedback suggests making the test assertion more robust by checking for a broader error message prefix rather than asserting the exact type uint64_t.
| # The import must fail, but with a readable error rather than a crash. | ||
| assert proc.returncode != -signal.SIGSEGV, proc.stderr | ||
| assert proc.returncode != 0 | ||
| assert 'Cannot parse "0# comment" to uint64_t' in proc.stderr, proc.stderr |
There was a problem hiding this comment.
To make the test more robust against future changes to the type of RAY_memory_monitor_refresh_ms (or platform-specific type differences), we should avoid asserting the exact type uint64_t in the error message and instead check for the common prefix.
| assert 'Cannot parse "0# comment" to uint64_t' in proc.stderr, proc.stderr | |
| assert 'Cannot parse "0# comment"' in proc.stderr, proc.stderr |
Assert on `Cannot parse "0# comment"` instead of the full message, so the test does not depend on the declared type of `memory_monitor_refresh_ms`. Signed-off-by: RunguoLi <[email protected]>
|
Hi @rueian @jjyao, could one of you take a look when you have a moment? This fixes #49222 ( |
## 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]>
…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]>
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
This pull request has been automatically closed because there has been no more activity in the 14 days Please feel free to reopen or open a new pull request if you'd still like this to be addressed. Again, you can always ask for help on our discussion forum or Ray's public slack channel. Thanks again for your contribution! |
Description
import raysegfaults when anyRAY_*config environment variable has a malformed value:Root cause (gdb on the 2.55.1 wheel and on the master nightly
34562c2):src/ray/asio/asio_chaos.ccconstructs itsDelayManagerin a static initializer (auto &delay_manager = []{...}();), and that constructor callsRayConfig::instance().RayConfig's constructor parses everyRAY_*env var. A malformed value trips theRAY_CHECKinConvertValue, which builds aRayLog._raylet.sois still beingdlopen'd, beforeRayLog's static members inlogging.ccare initialized. The log call dereferences an uninitialized ostream (null vptr) and the process dies with SIGSEGV instead of printing the check failure.As far as I can tell this is the only static initializer in
src/raythat touchesRayConfig.Fix: make
DelayManagera function-local static constructed on first use (GetDelayManager()), soRayConfigis first touched after static initialization is complete.RAY_testing_asio_delay_usset, behaviour is unchanged: the manager is still built from config on the firstGetDelayUs()/Init()call.GetDelayUs()returns early before touching the manager.With the fix, the same command fails with the intended message instead of crashing:
A subprocess regression test is added to
python/ray/tests/test_ray_init.py. It asserts a non-zero exit that isn't SIGSEGV, and that theCannot parsemessage is in stderr.Related issues
Closes #49222
Not a duplicate: no open PR addresses this issue. The only PR referencing it, #49512 (closed unmerged), replaced the raw
gettidsyscall inutil.hon the suspicion thatGetTidwas at fault. This PR fixes the static-initialization-order cause shown in the backtrace above.Additional information
Tests run
Baseline (
7204ade) and patched wheels were built inquay.io/pypa/manylinux2014_x86_64:2026.01.02-1(the base of Ray's CI manylinux image, gcc 10 devtoolset) with identical flags. They were compared in fresh venvs on Linux x86_64, Python 3.11:RAY_memory_monitor_refresh_ms='0# comment' python -c "import ray"Cannot parse "0# comment" to uint64_tpython -c "import ray"(control)pytest python/ray/tests/test_ray_init.py -k malformedreturncode=-11)pytest python/ray/tests/test_ray_init.py(whole file)bazel test //src/ray/asio/tests:asio_defer_testNote: a native gcc 13 build of the same commit does not segfault. There the check fires and the log call happens to survive, but the static-init path is identical: the stack still goes through
_GLOBAL__sub_I_asio_chaos.cc, and the patch removes it. That's why the fix was validated against the release (manylinux) toolchain. The regression test only catches the crash on toolchains where the bug shows up, but it asserts the readable error everywhere.Lint: ruff, black, pydoclint, clang-format, the import-order check and the C++ inclusion check all pass on the changed files. cpplint isn't configured for
src/ray/asio/.AI assistance
Claude Code was used to investigate the root cause, write the patch and test, and draft this description. The change was reviewed by the submitter, and the tests above were run on a Linux x86_64 dev machine.