Skip to content

Add reserved-port exclusions to getFreePorts - #157

Merged
yiguodev merged 1 commit into
mainfrom
feat/exclude-fixed-ports
Sep 23, 2026
Merged

yiguodev merged 1 commit into
mainfrom
feat/exclude-fixed-ports

Conversation

@yiguodev

Copy link
Copy Markdown
Collaborator

Summary

getFreePorts(count, excludePorts?)
  validate count and excluded port numbers
  bind localhost TCP listeners
  skip excluded and already-selected ports
  release all listeners on success or failure
  • Add optional excludePorts to the Invoke payload while keeping API version 3 and the existing data.ports response.
  • Keep listeners open throughout selection, including rejected ports, to prevent duplicate results and repeated allocation of an excluded port.
  • Reject invalid exclusions and impossible counts; document behavior in English and Chinese.

Evidence

  • Before (source): callers could only specify a count, and each listener closed before the next port was selected.
    After: deterministic tests verify exclusions, distinct ports, listener lifetime and cleanup on errors, invalid inputs, and zero-count behavior. Invoke tests cover omitted fields, duplicate exclusions, and malformed payloads.
  • go test ./... -count=1 — passed on macOS.
  • git diff --check origin/main...HEAD — passed.
  • Native packaging and device integration were not rerun for this PR preparation.

Merge Danger

Door: two-way

No persistent data changes. Direct Go callers must adopt nodep.GetFreePorts(count, excludePorts) and pass nil when no exclusions are needed; the JSON field remains optional.

Blast Radius: API

Port selection temporarily holds TCP listeners until the batch completes. Returned ports are candidates, not reservations, and UDP availability is not checked.

Copilot AI lite review requested due to automatic review settings September 23, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@yiguodev
yiguodev merged commit 55cb29e into main Sep 23, 2026
3 checks passed
@yiguodev
yiguodev deleted the feat/exclude-fixed-ports branch September 23, 2026 03:29
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.

2 participants