-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[dotnet] Support IPv6 to find free tcp port via DualMode #16016
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
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍(Review updated until commit c37403d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to c37403d
Previous suggestions✅ Suggestions up to commit 7271623
|
I am done, but I don't know how to test it. |
On Linux, you can do something similar to what I describe in #16003. You probably want to test on a system setup for IPv4-only, IPv6-only, and Mixed/Dual-stack. I'm not sure how to approach that on other Operating Systems. |
This implementation via Plan B is test on production, and revert these changes as soon as users start posting new issues. |
Would it make sense to change the order (try IPv4 first)? That's what I did in Python. It doesn't make much difference, but I think it's more likely that a system is IPv4-only than IPv6-only (with dual-stack interface, it wouldn't matter)... so there wouldn't be the overhead of an exception in the more common scenario. |
I got IPv6 only test environment where I am able to test old/new behavior. Give me a chance to fine tune this PR. |
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.
Pull Request Overview
This PR refactors the free port discovery method to prefer an IPv6 socket binding (with automatic disposal) and fallback to IPv4 on SocketException
.
- Attempt binding an IPv6 socket to a loopback endpoint and return its port
- Catch
SocketException
to retry binding on an IPv4 loopback endpoint - Simplify resource management with
using var
instead of manual socket lifecycle
Comments suppressed due to low confidence (1)
dotnet/src/webdriver/Internal/PortUtilities.cs:41
- There’s no test covering the IPv6 binding failure path; consider adding a unit test that simulates or forces a
SocketException
on IPv6 to verify the IPv4 fallback.
using var socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
IMHO it is done, there is no try/catch performance penalty. I tested it on "v4 + v6" and "v6 only". Hopefully it works on "v4 only". Now plan B is as soon as somebody reports that dual mode is not supported, then we will try/catch his environment and fall back to v4. |
User description
💥 What does this PR do?
Contributes to #14910
🔧 Implementation Notes
Seems it might throw here (if dual mode not supported?):
Then in future just wrap it to
try/catch
and fallback toipv4
only.PR Type
Enhancement
Description
Replace Socket-based port finding with TcpListener approach
Add IPv6 support with IPv4 fallback mechanism
Improve resource disposal and error handling
Simplify code structure and remove manual socket management
Changes diagram
Changes walkthrough 📝
PortUtilities.cs
Modernize port finding with IPv6 support
dotnet/src/webdriver/Internal/PortUtilities.cs