Skip to content
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

[🐛 Bug]: FindFreePort method hardcoded for IPv4 causing failure for pure IPv6 environments #14910

Open
SitrucHtims opened this issue Dec 18, 2024 · 4 comments · May be fixed by #14913
Open
Labels
C-dotnet help wanted Issues looking for contributions I-defect

Comments

@SitrucHtims
Copy link

What happened?

When running Selenium on a "pure IPv6" system where all IPv4 interfaces have been removed, the FindFreePort method, which is used to find a free TCP port to use on the loopback interface for communication to the browser driver, fails since it is hard coded for IPv4 and there are no IPv4 interfaces.

(https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Internal/PortUtilities.cs) Line 40
Socket portSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

AddressFamily.InterNetwork is IPv4. AddressFamily.InterNetworkV6 is IPv6.

In Pure IPv6 environment, attempt create the Browser Driver object fails with exception: "An address incompatible with the requested protocol was used"

How can we reproduce the issue?

On windows host where selenium is being executed:
-Ensure IPv6 is working as expected
-Remove IPv4 by running:  netsh interface ipv4 uninstall
-Reboot for uninstall to complete
-Attempt to use Selenium

The below PowerShell code could be used for example. Just place the WebDriver.dll and selected browserdriver.exe in the same directory as the saved PowerShell script and execute:

Function Get-Browser {
    Param (
           [Parameter(Mandatory=$true)]
           [ValidateSet("Edge","Chrome")]
           [string]$type
          )
    
    Set-EnvironmentPath

    Add-Type -Path "$($PSScriptRoot)\WebDriver.dll"

    Switch ($type) {
          "edge" {
                  $Driver = New-Object OpenQA.Selenium.Edge.EdgeDriver
                 }
        "chrome" {
                  $Driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
                 }
    }
    $Driver
}

Function Set-EnvironmentPath {
    # Add the working directory of script to the environment path.
    # This is required for the WebDriver to work.
    if (($env:Path -split ';') -notcontains $PSScriptRoot)
    {
        Write-Verbose -Message "Enviornment path does not contain $PSScriptRoot.  Adding to Path"
        if ($env:Path.Substring($env:Path.Length-1) -eq ';')
        {
            $env:Path += "$PSScriptRoot"
        }
        else
        {
            $env:Path += ";$PSScriptRoot"
        }
    }
}

$browser = Get-Browser -type Edge

Relevant log output

New-Object : Exception calling ".ctor" with "0" argument(s): "An address incompatible with the requested protocol was used"
At C:\WebDev\Start-Selenium.ps1:14 char:29
+ ...                  $Driver = New-Object OpenQA.Selenium.Edge.EdgeDriver
+                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Operating System

Windows 2019

Selenium version

PowerShell

What are the browser(s) and version(s) where you see this issue?

Edge 131.0.2903.86

What are the browser driver(s) and version(s) where you see this issue?

Microsoft Edge WebDriver 131.0.2903.99 (f96a870b1316f430223b7df17df32918b222060e)

Are you using Selenium Grid?

No

Copy link

@SitrucHtims, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Dec 18, 2024

Would you like to help us with a pull request?

@diemol diemol added C-dotnet help wanted Issues looking for contributions and removed needs-triaging labels Dec 18, 2024
Copy link

This issue is looking for contributors.

Please comment below or reach out to us through our IRC/Slack/Matrix channels if you are interested.

@Delta456
Copy link
Contributor

I can work on this

@Delta456 Delta456 linked a pull request Dec 18, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-dotnet help wanted Issues looking for contributions I-defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants