Skip to content

[1/n] IPv6 support: address <-> host:port conversion for Python Part - #55281

Merged
jjyao merged 3 commits into
ray-project:masterfrom
Yicheng-Lu-llll:python-ip-port-utils
Aug 8, 2025
Merged

jjyao merged 3 commits into
ray-project:masterfrom
Yicheng-Lu-llll:python-ip-port-utils

Conversation

@Yicheng-Lu-llll

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

Copy link
Copy Markdown
Member

Why are these changes needed?

Provide utilities that supports both ipv4 and ipv6 to combine host and port to address and split address to host and port.

This is a continuation of the work in #54662 (comment) and #55129. Please refer to the 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've implemented foundational changes to enhance Ray's network address handling, primarily to improve IPv6 support. This involved introducing a pair of core utility functions, parse_address and build_address, which provide a standardized and robust way to convert between host:port strings and their constituent parts, with special attention to IPv6 formatting. Following this, I've systematically refactored a large portion of the existing codebase to leverage these new utilities, replacing disparate and less robust string manipulation methods. This effort aims to ensure consistent and correct network communication across all Ray components, paving the way for full IPv6 compatibility.

Highlights

  • New Network Address Utilities: I've introduced two new core utility functions, parse_address and build_address, located in ray/_private/network_utils.py. These functions provide a standardized and robust way to handle network addresses (host:port strings) throughout the Ray codebase.
  • Enhanced IPv6 Compatibility: The build_address function now intelligently formats IPv6 addresses by enclosing them in square brackets (e.g., [::1]:8000), which is essential for correct parsing and communication in IPv6 environments. This ensures Ray components can properly interact over IPv6.
  • Extensive Code Refactoring: I've systematically refactored a significant portion of the Python codebase to replace various ad-hoc string manipulations (like .split(':') or f-strings) with calls to the new parse_address and build_address utilities. This change improves code consistency, readability, and correctness, especially when dealing with complex IPv6 addresses.
  • Broad System-Wide Impact: This refactoring impacts a wide array of Ray's internal components, including internal APIs, metrics agents, node management, dashboard services, autoscalers, data and serve modules, and numerous test utilities. This broad adoption ensures a consistent approach to address handling across the entire system.
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 build_address and parse_address utility functions for robust handling of network addresses, including IPv6. The changes are largely a mechanical replacement of manual string operations with these new functions, which is a significant improvement for IPv6 support. The implementation of the new utilities is sound. I've identified one critical issue where build_address is misused for Docker port mappings, which could lead to incorrect behavior. I've also provided a suggestion to simplify the implementation of build_address for better maintainability. Overall, this is a valuable contribution to the project.

Comment thread python/ray/_private/network_utils.py Resolved
@Yicheng-Lu-llll
Yicheng-Lu-llll force-pushed the python-ip-port-utils branch 3 times, most recently from ae5f646 to 78bfd1a Compare August 6, 2025 03:16
@ray-gardener ray-gardener Bot added community-contribution Contributed by the community core Issues that should be addressed in Ray Core labels Aug 6, 2025

@codope codope 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.

Overall looks good. Thanks for refactoring. One comment related to docker.

Comment thread python/ray/_private/network_utils.py 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.

How does it handle the docker port mapping? Docker's -p option can take the form ip:host_port:container_port. If build_address is used to generate the ip:host_port part of this string, it will correctly produce [ip]:host_port for an IPv6 address. However, the code that constructs the full port mapping string needs to be aware of this. I suggest covering this scenario in conftest_docker.py if not already done so.

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.

Thanks for the suggestion! We're already using build_address() in conftest_docker.py (see line 129). Let me know if I missed anything!

Comment thread python/ray/_private/node.py 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.

I found that the primary_redis_ip and port are actually unused.

@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.

(defering to core team; let me know if needs me)

@robertnishihara robertnishihara mentioned this pull request Aug 7, 2025
3 of 8 tasks
Comment thread python/ray/_private/network_utils.py 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.

Could you move this file to python/ray/_common/network_utils.py.

Comment thread python/ray/util/spark/cluster_init.py 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.

no need to change this, this is comment

@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.

LG!

@jjyao

jjyao commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

Could you also rebase and resolve merge conflicts.

@jjyao jjyao added the go add ONLY when ready to merge, run all tests label Aug 8, 2025

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.

Let's not change this since it's doc.

Comment thread python/ray/_common/network_utils.py 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.

Can you add some tests? In the follow-up, we can explore combining this with the c++ version via cython.

@bveeramani bveeramani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stamp

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.

I think you need main function

Signed-off-by: Yicheng-Lu-llll <[email protected]>
Signed-off-by: Yicheng-Lu-llll <[email protected]>
@jjyao
jjyao merged commit 7b44918 into ray-project:master Aug 8, 2025
dioptre pushed a commit to sourcetable/ray that referenced this pull request Aug 20, 2025
jugalshah291 pushed a commit to jugalshah291/ray_fork that referenced this pull request Sep 11, 2025
dstrodtman pushed a commit to dstrodtman/ray that referenced this pull request Oct 6, 2025
dstrodtman added a commit that referenced this pull request Oct 13, 2026
## Why are these changes needed?

Some files under `doc/source/core/` aren't shown on any docs page, and
nothing else in the repo references them. Docs example code should
either appear on a page, be a test wrapper for content that does, or be
deleted. This PR applies that rule to Ray Core:

| File | Status before | Change |
| --- | --- | --- |
| `doc_code/original_resource_unavailable_example.py` | Run by the
`source/core/doc_code/*.py` catch-all in `doc/BUILD.bazel`. #24544 added
it as a `literalinclude` on the placement group page, and a later
rewrite of that page dropped the include. It demonstrates scheduling a
task into a placement group's reserved CPUs, not a regression check, so
it isn't worth moving into `python/ray/tests/`. | Deleted |
| `examples/lm/` (`ray_train.py`, `ray_train.sh`, `preprocess.sh`,
`lm-cluster.yaml`) | Not tested. Referenced only by each other. Pins
`fairseq==0.8.0` and is what's left of a removed fairseq language-model
example. Its only recent edits are repo-wide sweeps such as the IPv6
work in #55281, #56147, and #58304. | Deleted |
| `examples/rdt/grpo_contextual_bandits.py` | Not tested. No page
includes it. #57961 added it as the companion script for the [Ray Direct
Transport blog
post](https://anyscale.com/blog/ray-direct-transport-rdma-support-in-ray-core),
which links to it by commit permalink
(`blob/c4f0c24.../doc/source/ray-core/examples/rdt/...`), so the blog
link keeps working after this deletion. | Deleted |

The catch-all's `exclude` list doesn't change. Deleting
`original_resource_unavailable_example.py` only removes the one test
target the glob generated for it.

### Questions for Ray Core maintainers

Please confirm or push back per file:

- `original_resource_unavailable_example.py`: if you'd rather keep this
behavior under test, I can move it to `python/ray/tests/` instead of
deleting it.
- `examples/rdt/grpo_contextual_bandits.py`: was a docs page planned for
it? If so, I can keep the script and add a page with a `literalinclude`
and a test instead. If the RDT team wants it kept as a standalone
example, say where it should live.

## Related issue number

None. I searched open PRs for each filename and found no overlap.

## Checks

- [x] I've signed off every commit (DCO).
- [x] `pre-commit run --files <changed files>`: passed, including the
master-link check.
- [x] `git grep` for `examples/lm`, `examples/rdt`,
`original_resource_unavailable`, and `grpo_contextual`: no remaining
references.
- [ ] I didn't run a local Sphinx build. No page referenced these files.

AI assistance (Claude Code) was used to prepare this PR. I reviewed
every changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

9 participants