-
Notifications
You must be signed in to change notification settings - Fork 25
π daily merge: fix_runtime_env_port β upstream_2.46.0 2025-11-17 #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: upstream_2.46.0
Are you sure you want to change the base?
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the port allocation logic in _get_unused_port to use a configurable environment-based port range rather than an arbitrary high-number range. Class diagram for updated _get_unused_port logic in NodeclassDiagram
class Node {
_get_unused_port(allocated_ports=None)
}
Node : +_get_unused_port(allocated_ports=None)
Node : - Uses os.getenv("RAY_PORT_RANGE_LOW", 10000)
Node : - Uses os.getenv("RAY_PORT_RANGE_HIGH", 11499)
Node : - random.randint(low_end, high_end)
Node : - Allocated ports checked
Flow diagram for new port allocation logic in _get_unused_portflowchart TD
A["Start _get_unused_port"] --> B["Get RAY_PORT_RANGE_LOW from env (default 10000)"]
B --> C["Get RAY_PORT_RANGE_HIGH from env (default 11499)"]
C --> D["For NUM_PORT_RETRIES times"]
D --> E["Generate 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @antfin-oss, 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 a crucial enhancement to Ray's port allocation strategy by making the range for generating unused ports configurable through environment variables. This modification provides greater control over port selection, aiming to prevent conflicts, particularly those encountered by GRPC, and thereby improving the overall stability and reliability of the Ray runtime environment. Highlights
Using Gemini Code AssistThe 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
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 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. 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. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `python/ray/_private/node.py:979-980` </location>
<code_context>
s.bind(("", 0))
port = s.getsockname()[1]
+ low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000))
+ high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499))
+
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider validating that low_end is less than or equal to high_end.
A check for low_end > high_end would prevent ValueError from random.randint and provide a clearer error message if environment variables are misconfigured.
```suggestion
low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000))
high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499))
if low_end > high_end:
raise ValueError(
f"Invalid port range: RAY_PORT_RANGE_LOW ({low_end}) is greater than RAY_PORT_RANGE_HIGH ({high_end}). "
"Please check your environment variable configuration."
)
```
</issue_to_address>Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
| low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000)) | ||
| high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider validating that low_end is less than or equal to high_end.
A check for low_end > high_end would prevent ValueError from random.randint and provide a clearer error message if environment variables are misconfigured.
| low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000)) | |
| high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499)) | |
| low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000)) | |
| high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499)) | |
| if low_end > high_end: | |
| raise ValueError( | |
| f"Invalid port range: RAY_PORT_RANGE_LOW ({low_end}) is greater than RAY_PORT_RANGE_HIGH ({high_end}). " | |
| "Please check your environment variable configuration." | |
| ) |
There was a problem hiding this comment.
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 configurable port ranges for the runtime environment, which is a good improvement for avoiding port conflicts. My review focuses on making the new implementation more robust by adding validation and safer type conversions for the environment variables. I've provided a single comment with a code suggestion to address these points.
| low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000)) | ||
| high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499)) | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation has a couple of potential issues:
- Unsafe type conversion: Using
int(os.getenv(...))can raise aValueErrorif the environment variable is set to a non-integer string (e.g., an empty string), which would crash the process. It's safer to use theray_constants.env_integerhelper, which handles this gracefully. - Lack of range validation: If
low_endis greater thanhigh_end,random.randint()will raise aValueError. It's best to validate the range and handle this case, for example by swapping the values and logging a warning.
Here is a suggestion that addresses both points.
| low_end = int(os.getenv("RAY_PORT_RANGE_LOW", 10000)) | |
| high_end = int(os.getenv("RAY_PORT_RANGE_HIGH", 11499)) | |
| low_end = ray_constants.env_integer("RAY_PORT_RANGE_LOW", 10000) | |
| high_end = ray_constants.env_integer("RAY_PORT_RANGE_HIGH", 11499) | |
| if low_end > high_end: | |
| logger.warning(f"RAY_PORT_RANGE_LOW ({low_end}) > RAY_PORT_RANGE_HIGH ({high_end}). Swapping.") | |
| low_end, high_end = high_end, low_end |
This Pull Request was created automatically to merge the latest changes from
fix_runtime_env_portintoupstream_2.46.0branch.π Created: 2025-11-17
π Merge direction:
fix_runtime_env_portβupstream_2.46.0π€ Triggered by: Manual
Please review and merge if everything looks good.
Summary by Sourcery
Merge fix_runtime_env_port branch into upstream_2.46.0 to support configurable port ranges for runtime environment.
Enhancements: