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

IPGlobalProperties.GetActiveTcpListeners() throws System.OverflowException on WSL #26730

Closed
iftahbe opened this issue Jul 9, 2018 · 7 comments
Assignees
Labels
area-System.Net bug help wanted [up-for-grabs] Good issue for external contributors os-windows-wsl WSL (Windows Subsystem for Linux) OS - Linux binaries running on Windows
Milestone

Comments

@iftahbe
Copy link

iftahbe commented Jul 9, 2018

Running on Ubuntu WSL (Windows Subsystem for Linux):

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

With dotnet (installed via apt-get install dotnet-sdk-2.1):

# dotnet --version
2.1.301

When I run the following console app:

using System;
using System.Net.NetworkInformation;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var ipProperties = IPGlobalProperties.GetIPGlobalProperties();
            var activeTcpListeners = ipProperties.GetActiveTcpListeners();
        }
    }
}

I get an exception:

System.OverflowException: Array dimensions exceeded supported range.
   at System.Net.NetworkInformation.StringParsingHelpers.ParseActiveTcpListenersFromFiles(String tcp4ConnectionsFile, String tcp6ConnectionsFile)
   at System.Net.NetworkInformation.LinuxIPGlobalProperties.GetActiveTcpListeners()
   at ConsoleApp3.Program.Main(String[] args) in /home/iftah/test/Program.cs:line 13
@stephentoub
Copy link
Member

This appears to be an issue with WSL: both /proc/net/tcp and /proc/net/tcp6 are empty. We should have a better failure mode from GetActiveTcpListeners in that case, but as GetActiveTcpListeners depends on those for the data, if the data isn't available, it probably still needs to throw, but just throw something more informative, like NetworkInformationException.

@wfurt
Copy link
Member

wfurt commented Aug 20, 2019

we should check if this is still issue.

@ManickaP
Copy link
Member

ManickaP commented Sep 5, 2019

I'll look into it.

@ManickaP
Copy link
Member

This does not happen on WSL2, mentioned files are not empty anymore and contain at least the expected header (e.g.: // First line is header in each file.).

I was able to reproduce the issue on WSL1 and the stated method is not the only one having problems.

I'll fix this since the fix is pretty easy.

@ManickaP
Copy link
Member

@stephentoub You suggested throwing NetworkInformationException but it inherits from Win32Exception so it might not be the best candidate (as it is right now).

I see 3 options right now:

  • split the NetworkInformationException into Win and Linux implementations
  • create a new, completely different exception
  • use another existing exception, e.g. PlatformNotSupportedException which is already used for when the file doesn't exist

@stephentoub
Copy link
Member

it inherits from Win32Exception

We've had to accept the fact that "Win32Exception" is simply poorly named, and it's really "OSException". It works fine on Unix, and is thrown in many other places. It'd be a breaking change to change NetworkInformationException's base type, and NetworkInformationException similarly works fine on Unix.

@ManickaP
Copy link
Member

Won't fix as this is only observed only on WSL1 and nowhere else.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 5.0 milestone Jan 31, 2020
@ManickaP ManickaP mentioned this issue Mar 3, 2020
25 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net bug help wanted [up-for-grabs] Good issue for external contributors os-windows-wsl WSL (Windows Subsystem for Linux) OS - Linux binaries running on Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants