Skip to content

fix(utils): report free port search exhaustion - #9870

Open
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/free-port-exhaustion
Open

fix(utils): report free port search exhaustion#9870
RerankerGuo wants to merge 1 commit into
modelscope:mainfrom
RerankerGuo:fix/free-port-exhaustion

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

find_free_port() returned the last candidate even when every bind attempt
failed. Deploy and app argument initialization could therefore accept an
occupied port and only fail later when starting the server.

This change:

  • returns immediately after a successful bind, preserving the existing path;
  • raises a clear OSError after exhausting the candidate range;
  • prevents retries near port 65535 from scanning invalid port numbers;
  • validates invalid starting ports and retry counts.

The change is limited to port selection. It does not reserve the returned port
or alter the existing bind interface.

Experiment results

Before:

find_free_port(30000, retry=3) -> 30002

when all three mocked bind attempts raised OSError.

After:

OSError: No free port found in range [30000, 30003)

Verification:

.venv/bin/python tests/run.py --test_dir tests/utils --pattern test_port_utils.py
SUCCESS (Runs=3, success=3)

.venv/bin/pre-commit run --files swift/utils/utils.py tests/utils/test_port_utils.py
All hooks passed

Raise a clear error when every candidate port is occupied and keep high-range scans within the valid TCP port range.

Test: python tests/run.py --test_dir tests/utils --pattern test_port_utils.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant