ant-ray
ant-ray copied to clipboard
[WIP] fix runtime env agent port conflict
Why are these changes needed?
Related issue number
Checks
- [ ] I've signed off every commit(by using the -s flag, i.e.,
git commit -s) in this PR. - [ ] I've run
scripts/format.shto lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I added a
method in Tune, I've added it in
doc/source/tune/api/under the corresponding.rstfile.
- [ ] I've added any new APIs to the API Reference. For example, if I added a
method in Tune, I've added it in
- [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
- [ ] Unit tests
- [ ] Release tests
- [ ] This PR is not tested :(
Summary by Sourcery
Restrict the random port selection for the runtime environment agent to a configurable range to avoid port conflicts.
Bug Fixes:
- Use RAY_PORT_RANGE_LOW and RAY_PORT_RANGE_HIGH environment variables (defaulting to 10000–11499) to bound the random port selection
- Prevent selecting ports outside the configured range instead of using the full ephemeral port range
Reviewer's guide (collapsed on small PRs)
Reviewer's Guide
Constrain the random port allocation in the node’s _get_unused_port method to a configurable environment-based range to prevent conflicts with other processes.
Class diagram for updated _get_unused_port method in Node
classDiagram
class Node {
+_get_unused_port(allocated_ports=None)
+low_end : int (from env RAY_PORT_RANGE_LOW)
+high_end : int (from env RAY_PORT_RANGE_HIGH)
+new_port : int (random in [low_end, high_end])
}
Flow diagram for port allocation with environment-based range
flowchart TD
A["Start _get_unused_port()"] --> B["Read RAY_PORT_RANGE_LOW and RAY_PORT_RANGE_HIGH from environment"]
B --> C["Set low_end and high_end"]
C --> D["For NUM_PORT_RETRIES times"]
D --> E["Pick new_port = random.randint(low_end, high_end)"]
E --> F["Check if new_port in allocated_ports"]
F -->|Yes| G["Skip port"]
F -->|No| H["Return new_port"]
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Introduce configurable port range for _get_unused_port |
|
python/ray/_private/node.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Summary of Changes
Hello @xsuler, I'm Gemini Code Assist[^1]! 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 addresses a recurring issue where Ray agents encounter port conflicts, particularly affecting GRPC communication, by allowing the system to select dynamic ports from a user-defined or default restricted range. This change enhances the stability and reliability of Ray's runtime environment by preventing agents from binding to ports that are already in use or fall outside acceptable operational boundaries.
Highlights
- Configurable Port Range: Introduced environment variables
RAY_PORT_RANGE_LOW(default 10000) andRAY_PORT_RANGE_HIGH(default 11499) to define a configurable range for dynamically allocated ports. - Port Conflict Resolution: Modified the
_get_unused_portfunction to select a random port exclusively within the newly definedRAY_PORT_RANGE_LOWandRAY_PORT_RANGE_HIGHboundaries, directly addressing GRPC port conflicts as noted in issue #8254.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| 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 pull request 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 :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
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.
[^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.
This pull request has been automatically marked as stale because it has not had any activity for 14 days. It will be closed in another 14 days if no further activity occurs. Thank you for your contributions.
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 has been merged in https://github.com/antgroup/ant-ray/pull/682