Repository navigation
[Core] After a failed ray:// connect, a local ray.init() raises a bare AssertionError #67142
Description
What happened + What you expected to happen
After ray.init("ray://...") fails, the process stays in Ray Client mode, and a later local ray.init() in that process raises a bare AssertionError that doesn't say what went wrong:
ray:// connect failed: ConnectionError ray client connection timeout
local ray.init() failed: AssertionError
The assertion is assert ray.experimental.internal_kv._internal_kv_initialized() in _record_stats in python/ray/_private/node.py. It fails because _ClientContext.connect in python/ray/util/client/__init__.py calls _explicitly_enable_client_mode() before connecting, and on failure its except calls only the per-context disconnect(), which never resets the flag. Only the module-level ray.util.disconnect() calls _explicitly_disable_client_mode().
Expected: after the first ray:// connect fails, a local ray.init() still fails, but with an error that says Ray Client is already initialized. instead of a bare AssertionError. A later ray.init("ray://<live address>", allow_multiple=True) already connects on master and must keep working.
As a workaround, call ray.util.disconnect() after the failed connect.
Versions / Dependencies
Reproduces on master 18b179a, Python 3.12.13, Linux.
Reproduction script
Run everything in one shell with auth off on both the head and the driver, and keep the head running:
export RAY_AUTH_MODE=disabled
ray start --head
python repro.pyIf the driver doesn't set RAY_AUTH_MODE=disabled, the local ray.init() raises AuthenticationError instead, because the driver uses token auth against a cluster that has it disabled. If no head is running, the last call times out because nothing listens on port 10001.
import ray
from ray._common.network_utils import find_free_port
try:
# Nothing listens on this port.
ray.init(f"ray://127.0.0.1:{find_free_port()}")
except ConnectionError as e:
print("ray:// connect failed:", type(e).__name__, e)
try:
ray.init() # Today: bare AssertionError in node.py _record_stats
except Exception as e:
print("local ray.init() failed:", type(e).__name__, e)
# Connects on master today; must keep working after the fix.
ray.init("ray://127.0.0.1:10001", allow_multiple=True)
print("allow_multiple=True connect succeeded")Issue Severity
Low: It annoys or frustrates me.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
justinyeh1995 commentedon Oct 18, 2026
/take I would like to look into this issue.
[-][Core] A failed ray:// connect leaves Ray Client mode on, breaking a later local ray.init()[/-][+][Core] After a failed ray:// connect, ray.init() raises a bare AssertionError and an allow_multiple=True retry times out[/+]justinyeh1995 commentedon Oct 24, 2026
Hi @MortalHappiness, I noticed the second expected behavior is resolved on
masterwhile reproducing the errors with the script belowI haven't looked into what've changed between cd9a46e and master but this could suggest the fix can scope down to just adding the error message.
justinyeh1995 commentedon Oct 26, 2026
Hi @Kissshot-2003, I've already taken this issue last week and I intent to finish it. Thanks.
justinyeh1995 commentedon Oct 27, 2026
Hi @MortalHappiness, I'd like to clarify on the expected behavior when the first ray:// connection succeeds and a following
ray.init()is called.Currently, it will not raise any issue despite it is using client mode under the hood. I assume this should still hold after the fix but I'd like to confirm with you first before jumping into a conclusion.
I'm a bit unsure cause the expected error message in the description says
Ray Client is already initialized, which makes even more sense on the successful execution path.Thank you
MortalHappiness commentedon Oct 27, 2026
Did you run my reproduction script? I ran it again myself and it still fails on master branch. What I want is:
ray.init() # Today: bare AssertionError in node.py _record_statsline, it should not raiseAssertionError. Instead, it should be another error type containingRay Client is already initializedin the error message.ray.init("ray://127.0.0.1:10001", allow_multiple=True) # Today: ConnectionError, ray client connection timeoutline, it should not raise error. It should connect successfully.justinyeh1995 commentedon Oct 28, 2026
Thanks for clarifying!
Yes, to confirm this again, I ran the script on master at
a450e8d44b938a7523f8d647517e3485b116b233after rebuilding withbazel run //:gen_ray_pkg.ray.init("ray://127.0.0.1:10001", allow_multiple=True)connected without an exception. I ran it on python 3.10 and linux.Got it. I'll narrow #67407 so it only raises after a failed
ray://connection. Thank you.[-][Core] After a failed ray:// connect, ray.init() raises a bare AssertionError and an allow_multiple=True retry times out[/-][+][Core] After a failed ray:// connect, a local ray.init() raises a bare AssertionError[/+]MortalHappiness commentedon Oct 28, 2026
I updated the issue description, please check agian.
justinyeh1995 commentedon Oct 28, 2026
Thanks. I'll update the pr accordingly.
[core] Reset client mode after a failed Ray Client connect