-
Notifications
You must be signed in to change notification settings - Fork 668
Fix logic for ipv6 connections in is_port_available #4005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jdetter
wants to merge
6
commits into
master
Choose a base branch
from
jdetter/is-port-available-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−28
Conversation
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
egormanga
reviewed
Jan 12, 2026
4ef42b4 to
d10e7f5
Compare
jdetter
commented
Jan 14, 2026
| None => return false, // invalid host string => treat as not available | ||
| }; | ||
|
|
||
| let sockets = match get_sockets_info(AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6, ProtocolFlags::TCP) { |
Collaborator
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This grabs the socket info from the kernel instead of manually trying to bind to the port on the ipv4/ipv6 interfaces.
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 of Changes
updated:
The original implementation here used
bindto try to discover if a port is currently in use. This isn't reliable due to platform differences - especially on windows where it's apparently acceptable to have a service running on both0.0.0.0:3000and127.0.0.1:3000. This would cause bind to return successfully when we wanted it to fail. Also: binding on an ipv6 interface when a machine doesn't have ipv6 enabled caused random errors and it was too unreliable to be useful.This new implementation uses
get_socket_infowhich returns info on all sockets in use on the system. We can then look through this list to find services which conflict with our requested port.updated 1/14:
This PR now includes a fix for flaky CLI tests. Originally we were using
find_free_portto pick a random free port, but that was causing a race condition which resulted in test flakes. This PR fixes this issue by using127.0.0.1:0as the listen addr so the kernel will automatically pick a free port for us.API and ABI breaking changes
None
Expected complexity level and risk
1 - this is a pretty isolated check, unlikely to introduce larger issues.
Testing
I tested on macos, windows and linux: