Repository navigation
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @Basasuya, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces comprehensive support for IPv6 networking within Ray, enabling it to operate seamlessly in environments that primarily use IPv6, such as Kubernetes pods configured with host network mode. The changes involve updating core networking logic across various Ray components to correctly handle IPv6 addresses, improving address parsing, and introducing environment variables for explicit IPv6 preference and configuration.
Highlights
- Core IPv6 Support: Enabled various Ray components, including the runtime environment agent, dashboard agents, GRPC servers, and the remote PDB, to correctly bind to and communicate using IPv6 addresses. This is primarily controlled by the
RAY_PREFER_IPV6environment variable. - Robust IP/Port Parsing: Updated numerous instances of IP address and port parsing logic across the codebase (both Python and C++) from
split(':')torsplit(':', 1)or a customSplitIpPortutility. This ensures correct separation of the IP address from the port, especially for IPv6 addresses which can contain multiple colons (e.g.,[::1]:8000). - IPv6 Environment Variable Integration: Introduced and utilized
RAY_PREFER_IPV6andRAY_POD_IPV6environment variables to signal IPv6 preference and provide the specific pod's IPv6 address. This allows Ray to adapt its networking behavior accordingly, particularly for localhost resolution and external connectivity checks in IPv6 environments. - New Utility Functions: Added a new
is_ipv6_addresshelper function in Python (python/ray/_private/utils.py) and aSplitIpPortutility in C++ (src/ray/util/util.h) to reliably identify and parse IPv6 addresses, including handling bracket notation for IPv6 literals. - Torch Distributed and PDB Compatibility: Adjusted Torch distributed training setup to strip
[]from IPv6 master addresses for compatibility. Similarly, the remote PDB (rpdb) was updated to correctly handle IPv6 addresses for both listening and connecting sockets.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
| inline std::vector<std::string> SplitIpPort(const std::string &address) { | ||
| std::vector<std::string> result; | ||
| size_t found; | ||
| found = address.find_last_of(":"); | ||
| if (found == std::string::npos) { | ||
| return result; | ||
| } | ||
|
|
||
| result.push_back(address.substr(0, found)); | ||
| result.push_back(address.substr(found + 1)); | ||
| return result; | ||
| } |
There was a problem hiding this comment.
The SplitIpPort implementation incorrectly parses bare IPv6 addresses. The current implementation uses find_last_of(":") to split the address and port. This works for IPv4 but fails for bare IPv6 addresses (e.g., ::1), which it would incorrectly split into :: and 1. A more robust implementation should correctly handle different address formats, including bracketed IPv6 addresses. It will return an empty vector for bare IPv6 addresses, causing the existing RAY_CHECKs to fail, which is safer than mis-parsing the address.
inline std::vector<std::string> SplitIpPort(const std::string &address) {
std::vector<std::string> result;
if (address.empty()) {
return result;
}
// Handle IPv6 with brackets, e.g., [::1]:8080
if (address[0] == '[') {
size_t r_bracket_pos = address.rfind(']');
if (r_bracket_pos == std::string::npos) {
// Malformed address.
return result;
}
// Check for port after brackets.
if (r_bracket_pos + 1 < address.size() && address[r_bracket_pos + 1] == ':') {
result.push_back(address.substr(0, r_bracket_pos + 1));
result.push_back(address.substr(r_bracket_pos + 2));
return result;
}
// No port found.
return result;
}
// Handle IPv4 and bare IPv6.
size_t last_colon_pos = address.rfind(':');
if (last_colon_pos == std::string::npos) {
// No colon, no port.
return result;
}
// If there are multiple colons, it's a bare IPv6 address. Assume no port.
if (address.find(':') != last_colon_pos) {
return result;
}
// Only one colon. Assume it's a port separator for IPv4/hostname.
result.push_back(address.substr(0, last_colon_pos));
result.push_back(address.substr(last_colon_pos + 1));
return result;
}| my_pod_ip6 = os.environ.get("RAY_POD_IPV6") | ||
| if my_pod_ip6 is not None and my_pod_ip6 != "": | ||
| if len(address_parts) > 1: | ||
| return ip_address + ":" + os.environ.get("RAY_GCS_SPECIFIC_PORT", "6379") | ||
| else: | ||
| return ip_address | ||
| return ":".join([ip_address] + address_parts[1:]) |
There was a problem hiding this comment.
The condition my_pod_ip6 is not None and my_pod_ip6 != "" can be simplified to just if my_pod_ip6:1. Additionally, the use of os.environ.get("RAY_GCS_SPECIFIC_PORT", "6379") hardcodes a default port for GCS. This could be brittle if the GCS server is configured to run on a different port. Consider making this port resolution more robust instead of relying on a hardcoded default.
Style Guide References
| my_pod_ip6 = os.environ.get("RAY_POD_IPV6") | |
| if my_pod_ip6 is not None and my_pod_ip6 != "": | |
| if len(address_parts) > 1: | |
| return ip_address + ":" + os.environ.get("RAY_GCS_SPECIFIC_PORT", "6379") | |
| else: | |
| return ip_address | |
| return ":".join([ip_address] + address_parts[1:]) | |
| my_pod_ip6 = os.environ.get("RAY_POD_IPV6") | |
| if my_pod_ip6: | |
| if len(address_parts) > 1: | |
| # TODO(dev): Consider making this port resolution more robust | |
| # instead of relying on a hardcoded default. | |
| return ip_address + ":" + os.environ.get("RAY_GCS_SPECIFIC_PORT", "6379") | |
| else: | |
| return ip_address |
Footnotes
| # SubscriberID / UniqueID, which is 28 (kUniqueIDSize) random bytes. | ||
| subscriber_id = bytes(bytearray(random.getrandbits(8) for _ in range(28))) | ||
| gcs_address, gcs_port = address.split(":") | ||
| gcs_address, gcs_port = address.rsplit(":", 1) |
There was a problem hiding this comment.
If address is "[::1]:6379", gcs_address remains "[::1]". The C++ subscriber likely expects a bare IP without brackets. I think you need to strip the brackets [/] before passing into the C++ API (or preferably use a helper that handles both cases, and the helper method can be unit tested).
| return in_test | ||
|
|
||
|
|
||
| def is_ipv6_address(ip): |
There was a problem hiding this comment.
This method strips leading [] but won’t accept link-local addresses with a zone ID (e.g. "fe80::1%eth0"). If some environment use such addresses, you’ll need to extend the util to handle %-notation correctly.
Also, this method looks like a good candidate to move to python/ray/_common instead of _private. Let's also add comprehensive unit tests for this method in python/ray/_common/tests/test_utils.py
| Opens a remote PDB on first available port. | ||
| """ | ||
| if debugger_external: | ||
| if os.environ.get("RAY_PREFER_IPV6") is not None: |
There was a problem hiding this comment.
I noticed some inconsistent checks. For example, here we check for the env variable but never verify its value. And at some places like in http_server_agent.py, we also check for value. Consider keeping the checks consistent. Another suggestion is to check for os.environ.get("RAY_PREFER_IPV6", "").lower().
| } | ||
| RAY_CHECK_EQ(parts.size(), 3u); | ||
| std::vector<std::string> ip_port = absl::StrSplit(parts[2], ":"); | ||
| std::vector<std::string> ip_port = SplitIpPort(parts[2]); |
There was a problem hiding this comment.
Looks like this still assumes IPv4 addresses or use split(':'). Without corresponding changes, services started in pure-IPv6 mode may fail to bind or mis-advertise their ports?
| std::string server_address( | ||
| (listen_to_localhost_only_ ? "127.0.0.1:" : (use_ipv6 ? "[::]:" : "0.0.0.0:")) + | ||
| std::to_string(port_)); |
There was a problem hiding this comment.
Swapping "127.0.0.1" -> "::" without also binding "::1" (loopback) may expose the Dashboard, PDB, or control plane APIs on the host’s external IPv6 interface. Best practice is to bind local-only services to ::1 explicitly, and wildcard services (cluster-in traffic) to ::.
| """ | ||
| ip_address, port = address.split(":") | ||
| ip_address, port = address.rsplit(":", 1) | ||
| if ip_address == "8.8.8.8": |
There was a problem hiding this comment.
Why hard coded? Also, this breaks in IPv6-only environments
There was a problem hiding this comment.
ok i get it this is for DNS assuming 8.8.8.8 is always available. Is there a better way to resolve DNS?
There was a problem hiding this comment.
Please let's also add unit tests for this method to ensure it covers both IPv4 and IPv6 IPs.
There was a problem hiding this comment.
What if the server is not connected to the Internet? We might want to allow some env var for specifying a test DNS.
There was a problem hiding this comment.
This part use RAY_POD_IPV6 env to get the real node ip address which user set from ray start --node-ip-address=xxxxx.
That is to say, users use env to configure ip instead of obtaining it through DNS.
| inline std::vector<std::string> SplitIpPort(const std::string &address) { | ||
| std::vector<std::string> result; | ||
| size_t found; | ||
| found = address.find_last_of(":"); | ||
| if (found == std::string::npos) { | ||
| return result; | ||
| } | ||
|
|
||
| result.push_back(address.substr(0, found)); | ||
| result.push_back(address.substr(found + 1)); | ||
| return result; | ||
| } |
| """ | ||
| ip_address, port = address.split(":") | ||
| ip_address, port = address.rsplit(":", 1) | ||
| if ip_address == "8.8.8.8": |
There was a problem hiding this comment.
Please let's also add unit tests for this method to ensure it covers both IPv4 and IPv6 IPs.
| "127.0.0.1" if args.node_ip_address == "127.0.0.1" else "0.0.0.0" | ||
| ) | ||
|
|
||
| if os.environ.get("RAY_PREFER_IPV6") is not None: |
There was a problem hiding this comment.
On further discussion with @jjyao , this additional env variable might not be needed as node_ip_address will always be set. If the user sets node_ip_address explicitly then we infer whether that's an IPv4 or IPv6 address and bind to the user-specified port. All we need is a utility to tell whether the address is IPv4 and IPv6. If user does not explicitly set node_ip_address, then node_ip_address_from_perspective will deduce some ip address and then we call same utility as above.
There was a problem hiding this comment.
That is a good idea, this is the solution we could remove env RAY_PREFER_IPV6
| @@ -221,6 +221,9 @@ def parent_dead_callback(msg): | |||
| runtime_env_agent_ip = ( | |||
| "127.0.0.1" if args.node_ip_address == "127.0.0.1" else "0.0.0.0" | |||
There was a problem hiding this comment.
Currently we always bind to 0.0.0.0 unless user explicitly specify the node ip to be localhost. Let's use this opportunity to change to ONLY bind to the node ip address user specified via ray start --node-ip-address since all the clients will only connect to it via this ip and it's more secure.
There was a problem hiding this comment.
Since the pr is aiming at supporting ipv6, do we want to bind to "::" if the node_ip_address is ipv6?
Signed-off-by: Jiajun Yao <[email protected]>
|
I fix some bug when using ray job submit, watch ray logs after remove [] from node_ip_address some TODO:
welcome to add other point which I have not mentioned |
|
For easy review, we can break this PR into a few smaller ones. I think the first one can be creating two utils: one is combing ip and port to address, the other is split address to ip and port. And replace all the places in the codebase with these two utils. I can find someone to work on it. |
|
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! |
Why are these changes needed?
Some previous issues also describe requirements for the use of IPv6. I think IPv6 mode is important feature for Ray. Many online environments have IPv6 network cards, and ray could not running on machines which only support IPv6 cards.
In our enviroment, we are running ray in ipv6 host network mode kubernetes pod.
Related issue number
#54660
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.