fix: include port 65535 in free port search#2040
Conversation
Signed-off-by: nightcityblade <nightcityblade@gmail.com>
Greptile SummaryThis PR fixes an off-by-one error in
Confidence Score: 5/5Safe to merge — the change is a minimal, well-targeted one-character fix with a matching regression test. The fix is a single-integer change to the range upper bound, the error message was already consistent with the intended behavior, the Ray worker port exclusion range (10002–19999) is far from 65535 so the filter does not interfere, and the new test directly exercises the boundary via a focused fake socket. 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 worker\nrange 10002–19999?}
C -- Yes --> B
C -- No --> D["socket.bind('localhost', port)"]
D -- Success --> E["return port"]
D -- OSError --> F{get_next_free_port\nAND port == start_port?}
F -- Yes, first port --> G["raise RuntimeError\n(port in use)"]
F -- No --> B
B -- range exhausted --> H["raise RuntimeError\n(no free port 65535)"]
Reviews (1): Last reviewed commit: "fix: include port 65535 in free port sea..." | Re-trigger Greptile |
|
Closing in favor of #2024 which was opened first. |
Description
Closes #2023.
Updates
get_free_port()to include port 65535 in the search range, matching the valid TCP port range and the existing error message. Adds a focused regression test for starting the search at 65535.Usage
Checklist
Testing
uv run --python 3.12 --group linting ruff check nemo_curator/core/utils.py tests/core/test_utils.py— passeduv run --python 3.12 --group test python -m pytest tests/core/test_utils.py— blocked on macOS becausenemo_curatorraisesValueErroron non-Linux systems during importget_free_port(65535)and a fake socket — passed