[Core] Worker SIGSEGV in PyTraceBack_Here when LocalGC arrives before worker.core_worker is assigned
What happened + What you expected to happen
A worker segfaults (PyTraceBack_Here, ) if a LocalGC request reaches it during startup. The window is between the worker announcing its port to the raylet and Python assigning global_worker.core_worker. During that gap, gc_collect runs global_worker.core_worker.trigger_gc(), which raises AttributeError. The exception escapes a nogil callback and crashes the process, the same crash class as #54556 and #64558. Master has the same code.
We hit this in production. Frequent global GCs from WarnResourceDeadlock combined with high actor churn killed about 0.1% of new workers.
Expected: a GC request during startup is ignored instead of killing the worker.
Workaround: RAY_start_python_gc_manager_thread=0.
Suggested fix: in gc_collect, skip the call if core_worker isn't set yet, and wrap the body in try/except. Happy to send a PR.
Versions / Dependencies
Ray 2.51.1, Python 3.12.7, Linux x86_64.
Reproduction script
The sitecustomize delays the core_worker assignment by 0.5 s so the race always hits.
import os, sys, tempfile, time
d = tempfile.mkdtemp()
with open(os.path.join(d, "sitecustomize.py"), "w") as f:
f.write(
"import sys, time\n"
"if 'default_worker.py' in ' '.join(sys.argv):\n"
" import ray._raylet as r\n"
" _Real = r.CoreWorker\n"
" def _slow(*a, **kw):\n"
" cw = _Real(*a, **kw); time.sleep(0.5); return cw\n"
" r.CoreWorker = _slow\n"
)
os.environ["PYTHONPATH"] = d + os.pathsep + os.environ.get("PYTHONPATH", "")
os.environ["RAY_local_gc_min_interval_s"] = "0"
import ray
from ray._private.internal_api import global_gc
ray.init(num_cpus=4)
@ray.remote(num_cpus=0)
class A:
def ping(self):
return os.getpid()
deaths = 0
for _ in range(20):
actors = [A.remote() for _ in range(8)]
refs = [a.ping.remote() for a in actors]
end = time.time() + 2
while time.time() < end:
global_gc()
time.sleep(0.05)
for ref in refs:
try:
ray.get(ref, timeout=60)
except ray.exceptions.RayActorError:
deaths += 1
for a in actors:
ray.kill(a)
print(f"actor deaths: {deaths} / 160", file=sys.stderr)Output: actor deaths: 160 / 160, and every worker log shows the SIGSEGV. With RAY_start_python_gc_manager_thread=0: 0 / 160.
Issue Severity
Medium: It is a significant difficulty but I can work around it.
Source: ray-project/ray