Skip to content

[1/n] IPv6 support: address <-> host:port conversion - #55129

Closed
Yicheng-Lu-llll wants to merge 1 commit into
ray-project:masterfrom
Yicheng-Lu-llll:ip-port-utils
Closed

Yicheng-Lu-llll wants to merge 1 commit into
ray-project:masterfrom
Yicheng-Lu-llll:ip-port-utils

Conversation

@Yicheng-Lu-llll

@Yicheng-Lu-llll Yicheng-Lu-llll commented Aug 1, 2025 •

Copy link
Copy Markdown
Member

Why are these changes needed?

This is a continuation of the work in #54662 (comment).

Please refer to that discussion for more context

Related issue number

Checks

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Yicheng-Lu-llll, 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!

I am introducing the foundational changes for IPv6 support in Ray. This pull request focuses on establishing a consistent and correct way to handle the conversion between IP addresses (including IPv6) and host:port string representations across both Python and C++ components. By centralizing this logic, I am preparing the codebase for broader IPv6 compatibility in subsequent changes.

Highlights

  • New Network Utilities: I've added "parse_address" and "build_address" functions in "python/ray/_private/network_utils.py" and their C++ counterparts in "src/ray/common/network_util.cc" and ".h". These utilities correctly handle IPv6 addresses by enclosing them in square brackets "[]" when forming host:port strings.
  • Runtime Environment Agent IP Binding: I've updated the runtime environment agent to bind directly to "args.node_ip_address" instead of a hardcoded "127.0.0.1" or "0.0.0.0". This change allows the agent to correctly bind to IPv6 addresses if "node_ip_address" is an IPv6 address.
  • Refactored Address Parsing/Building: I've integrated the new "ParseAddress" and "BuildAddress" utilities into key Ray components, including the GCS client, Redis context, and gRPC client. This ensures that all address parsing and building operations are IPv6-aware and consistent.
  • Removed Redundant Function: The simple "address" helper function in "python/ray/_private/services.py" has been removed, as its functionality is now superseded by the more robust "build_address" utility.
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 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 or fill out our survey 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

  1. 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. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces utility functions for handling IPv6 addresses in both Python and C++, which is a good step towards full IPv6 support. The core logic for parsing and building addresses with host and port components has been added. My review focuses on the correctness and robustness of these new utility functions. I've identified some critical issues where the parsing logic for IPv6 addresses is incorrect, especially for addresses without ports. I've also pointed out that the logic for building addresses is not fully robust and can be improved by using standard library features for IP address validation in both Python and C++. The suggested changes aim to make these utilities more reliable and prevent potential bugs.

Comment thread python/ray/_private/network_utils.py Resolved
Comment thread src/ray/common/network_util.cc Resolved
Comment thread python/ray/_private/network_utils.py Resolved
Comment thread src/ray/common/network_util.cc Resolved
@Yicheng-Lu-llll
Yicheng-Lu-llll force-pushed the ip-port-utils branch 3 times, most recently from 387946e to 4dbb21c Compare August 1, 2025 20:36
Comment thread src/ray/common/network_util.cc Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we are not aiming to provide strict address validation, but rather to mimic the behavior of absl::StrSplit(ipv4_address, ':').

For example, in absl::StrSplit(ipv4_address, ':'):

If the ipv4_address contains a colon (:), it is assumed to be in the ip:port format and is split accordingly.

If the ipv4_address does not contain a colon, it returns [ipv4_address], treating it as an address without a specified port.

Similarly, ParseAddress provides the same behavior for IPv6:

If [2001:db8::1]:8000 is provided, it returns ["2001:db8::1", "8000"].

If 2001:db8::1 or even ::1 is provided, it simply returns ["2001:db8::1"] or ["::1"]

@jjyao jjyao added the go add ONLY when ready to merge, run all tests label Aug 1, 2025
@Yicheng-Lu-llll
Yicheng-Lu-llll force-pushed the ip-port-utils branch 2 times, most recently from e7fff3f to 74198aa Compare August 4, 2025 02:32
@Yicheng-Lu-llll Yicheng-Lu-llll changed the title WIP [1/n] IPv6 support: address <-> host:port conversion [1/n] IPv6 support: address <-> host:port conversion Aug 4, 2025
@Yicheng-Lu-llll
Yicheng-Lu-llll marked this pull request as ready for review August 4, 2025 06:26
@ray-gardener ray-gardener Bot added community-contribution Contributed by the community core Issues that should be addressed in Ray Core labels Aug 4, 2025

@aslonnie aslonnie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is changing a lot of files.. can we split this into smaller PRs and roll out this more incrementally?

@Yicheng-Lu-llll

Copy link
Copy Markdown
Member Author

this is changing a lot of files.. can we split this into smaller PRs and roll out this more incrementally?

The only changes here are:

  • Replacing manual ip + ':' + port logic with buildAddress
  • Replacing manual address splitting with parseAddress

These changes are intended to be fully backward compatible.
Let me know if it still feels like too much — happy to adjust if needed.

@jjyao jjyao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!!

Comment thread src/ray/util/util.h Outdated
Comment on lines 176 to 180

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a network_util.h|cc file for these?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add docstring for these methods.

Comment thread src/ray/util/util.cc Outdated
Comment on lines 258 to 260

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will we call this function without port?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is aim to mimic the behavior of split. For example, we currently have code where the input can be either a plain IP address or an IP address with a port (ip:port).

def resolve_ip_for_localhost(address: str):
"""Convert to a remotely reachable IP if the address is "localhost"
or "127.0.0.1". Otherwise do nothing.
Args:
address: This can be either a string containing a hostname (or an IP
address) and a port or it can be just an IP address.
Returns:
The same address but with the local host replaced by remotely
reachable IP.
"""
if not address:
raise ValueError(f"Malformed address: {address}")
address_parts = address.split(":")
if address_parts[0] == "127.0.0.1" or address_parts[0] == "localhost":
# Make sure localhost isn't resolved to the loopback ip
ip_address = get_node_ip_address()
return ":".join([ip_address] + address_parts[1:])
else:
return address

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there are two callers of resolve_ip_for_localhost. One pass in ip only and the other pass in ip:port. I'd actually make the function only accepts IP and do the split on the caller side. This makes the code cleaner.

Comment thread src/ray/protobuf/object_manager.proto Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the review easier, could you create a separate PR for this kind of pure format changes?

@jjyao

jjyao commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

Let me know if it still feels like too much — happy to adjust if needed.

Could you create a PR with only c++ changes and we can have another one with only python changes, this will make the PR smaller to review.

@Yicheng-Lu-llll

Copy link
Copy Markdown
Member Author

Let me know if it still feels like too much — happy to adjust if needed.

Could you create a PR with only c++ changes and we can have another one with only python changes, this will make the PR smaller to review.

Sure!

@Yicheng-Lu-llll

Yicheng-Lu-llll commented Aug 4, 2025 •

Copy link
Copy Markdown
Member Author

I have:

  • Add docstring for BuildAddress and ParseAddress
  • Moved BuildAddress and ParseAddress to network_util.h/.cc
  • Removed formatting changes to the proto file
  • Made resolve_ip_for_localhost accept only IP addresses

will soon separate the PR into C++ and Python changes and recheck every changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants