Skip to content

Commit b6f22ff

Browse files
committed
Update PortUtilities.cs
1 parent 80190d8 commit b6f22ff

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

dotnet/src/webdriver/Internal/PortUtilities.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ namespace OpenQA.Selenium.Internal;
2828
public 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;

0 commit comments

Comments
 (0)