Fix get_free_port checking port 65535#2044
Open
nightcityblade wants to merge 1 commit into
Open
Conversation
Signed-off-by: nightcityblade <nightcityblade@gmail.com>
Contributor
Greptile SummaryThis PR fixes an off-by-one bug in
Confidence Score: 5/5Safe to merge — the change is a minimal, well-tested one-line fix with no side effects on the rest of the port-scanning logic. The fix is a single-character range correction with clear intent, a matching regression test, and no impact on any other code path. Ray worker port exclusion (10002–19999) is unaffected, and the error message already says '65535' so it remains consistent with the new behaviour. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["get_free_port(start_port)"] --> B["for port in range(start_port, 65536)"]
B --> C{"port in Ray\nworker range?\n(10002–19999)"}
C -- Yes --> B
C -- No --> D["Try bind(localhost, port)"]
D -- "OSError\n(port busy)" --> E{"get_next_free_port\nAND port==start_port?"}
E -- No --> B
E -- Yes --> F["raise RuntimeError\n'Port already in use'"]
D -- Success --> G["return port"]
B -- "exhausted" --> H["raise RuntimeError\n'No free port found'"]
Reviews (1): Last reviewed commit: "Fix get_free_port checking port 65535" | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the inclusive upper bound in
get_free_port()so port 65535 is actually checked before raising.Closes #2023.
Usage
Checklist
Tests:
uv run ruff check nemo_curator/core/utils.py tests/core/test_utils.pyuv run python - <<'PY' ...custom focusedget_free_port(65534) == 65535harnessNote:
uv run pytest tests/core/test_utils.py -qcould not run on this macOS host because NeMo-Curator raises on non-Linux systems during import.