Skip to content

fix: use standard method to get random unused port#67

Merged
icota merged 1 commit into
Foundation-Devices:mainfrom
Cyrix126:main
May 27, 2026
Merged

fix: use standard method to get random unused port#67
icota merged 1 commit into
Foundation-Devices:mainfrom
Cyrix126:main

Conversation

@Cyrix126
Copy link
Copy Markdown
Contributor

Current way does not ask the system but tries randomly to find a port. It has drawbacks such as:

  • being less efficient that letting the system choose
  • let the system potentially offer the same port until it is really used. Since only the port is returned and the socket is closed, a race condition could occur where another application bind to the port between calling this function to get a port and actually using it.
    Asking the system will ensure it will not suggest the same port again even if it's not used until all other ports have been given. Otherwise we would need to pass the opened socket instead of just the port to avoid the potential race condition.

Copy link
Copy Markdown
Collaborator

@icota icota left a comment

Choose a reason for hiding this comment

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

Makes sense

@icota icota merged commit 36e1fa4 into Foundation-Devices:main May 27, 2026
1 check passed
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