File tree Expand file tree Collapse file tree 1 file changed +1
-3
lines changed
dotnet/src/webdriver/Internal Expand file tree Collapse file tree 1 file changed +1
-3
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,11 @@ namespace OpenQA.Selenium.Internal;
2828public static class PortUtilities
2929{
3030 /// <summary>
31- /// Finds a random, free port to be listened on.
31+ /// Finds a random, free port to be listened on. Prefers IPv4, but falls back to IPv6 if necessary.
3232 /// </summary>
3333 /// <returns>A random, free port to be listened on.</returns>
3434 public static int FindFreePort ( )
3535 {
36- // Prefer IPv4, but fall back robustly to IPv6
3736 try
3837 {
3938 using var ipV4socket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
@@ -42,7 +41,6 @@ public static int FindFreePort()
4241 }
4342 catch ( SocketException )
4443 {
45- // If creating/binding the IPv4 socket fails for any reason, fall back to IPv6
4644 using var ipV6socket = new Socket ( AddressFamily . InterNetworkV6 , SocketType . Stream , ProtocolType . Tcp ) ;
4745 ipV6socket . Bind ( new IPEndPoint ( IPAddress . IPv6Loopback , 0 ) ) ;
4846 return ( ( IPEndPoint ) ipV6socket . LocalEndPoint ! ) . Port ;
You can’t perform that action at this time.
0 commit comments