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

NetworkInformationException when querying network interfaces in WSL 1 #75883

Closed
f-markus opened this issue Sep 20, 2022 · 14 comments · Fixed by #76383
Closed

NetworkInformationException when querying network interfaces in WSL 1 #75883

f-markus opened this issue Sep 20, 2022 · 14 comments · Fixed by #76383

Comments

@f-markus
Copy link

f-markus commented Sep 20, 2022

Description

A customer reported the following exception. The code was executed inside WSL 1, the assembly was compiled with .NET 7.0 RC1. Recompiling everything with .NET6.0 resolves the issue.

System.Net.NetworkInformation.NetworkInformationException (2): An error was encountered while querying information from the operating system. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '/proc/sys/net/ipv4/conf/eth0/forwarding'.
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Func'4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func'4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable'1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at System.Net.NetworkInformation.StringParsingHelpers.ReadAllText(String filePath)
   at System.Net.NetworkInformation.StringParsingHelpers.ReadAllText(String filePath)
   at System.Net.NetworkInformation.StringParsingHelpers.ParseRawetFile(String filePath)
   at System.Net.NetworkInformation.LinuxIPv4InterfaceProperties.GetIsForwardingEnabled()
   at System.Net.NetworkInformation.LinuxIPInterfaceProperties..ctor(LinuxNetworkInterface lni, LinuxNetworkInterfaceSystemProperties systemProperties)
   at System.Net.NetworkInformation.LinuxNetworkInterface.GetLinuxNetworkInterfaces()
   at V4pCore.Common.Utils.Utilities.GetMacAddresses(Boolean addDetail) in E:\git-data\v3s_new\V4pCore\Common\Utils\Utilities.cs:line 22
   at V4pServer.Server.UpdateWorkspace(String reason)
   at V4pServer.Server.Initialized()
   at LanguageServer.Reflector.<>c__DisplayClass13_0'1.<ForNotification1>b__0(Object n, Connection c)

Reproduction Steps

I don't use WSL, but from the code it should be fairly easy to reproduce:
Just call
NetworkInterface.GetAllNetworkInterfaces()
from an app in WSL

Expected behavior

No exception, but a list of valid networkinterfaces

Actual behavior

Exception instead of list of network interfaces

Regression?

The very same code works with .NET6.0 as TargetPlatform

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 20, 2022
@ghost
Copy link

ghost commented Sep 20, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

A customer reported the following exception. The code was executed inside WSL 1, the assembly was compiled with .NET 7.0 RC1. Recompiling everything with .NET6.0 resolves the issue.

System.Net.NetworkInformation.NetworkInformationException (2): An error was encountered while querying information from the operating system. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '/proc/sys/net/ipv4/conf/eth0/forwarding'.
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Func'4 createOpenException)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func'4 createOpenException)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable'1 unixCreateMode)
at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
at System.IO.File.ReadAllText(String path, Encoding encoding)
at System.Net.NetworkInformation.StringParsingHelpers.ReadAllText(String filePath)
at System.Net.NetworkInformation.StringParsingHelpers.ReadAllText(String filePath)
at System.Net.NetworkInformation.StringParsingHelpers.ParseRawetFile(String filePath)
at System.Net.NetworkInformation.LinuxIPv4InterfaceProperties.GetIsForwardingEnabled()
at System.Net.NetworkInformation.LinuxIPInterfaceProperties..ctor(LinuxNetworkInterface lni, LinuxNetworkInterfaceSystemProperties systemProperties)
at System.Net.NetworkInformation.LinuxNetworkInterface.GetLinuxNetworkInterfaces()
at V4pCore.Common.Utils.Utilities.GetMacAddresses(Boolean addDetail) in E:\git-data\v3s_new\V4pCore\Common\Utils\Utilities.cs:line 22
at V4pServer.Server.UpdateWorkspace(String reason)
at V4pServer.Server.Initialized()
at LanguageServer.Reflector.<>c__DisplayClass13_0'1.b__0(Object n, Connection c)

Reproduction Steps

I don't use WSL, but from the code it should be fairly easy to reproduce:
Just call
NetworkInterface.GetAllNetworkInterfaces()
from an app in WSL

Expected behavior

No exception, but a list of valid networkinterfaces

Actual behavior

Exception instead of list of network interfaces

Regression?

The very same code works with .NET6.0 as TargetPlatform

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: f-markus
Assignees: -
Labels:

area-System.Net

Milestone: -

@wfurt
Copy link
Member

wfurt commented Sep 20, 2022

regression from #63696?
cc: @rzikm

@karelz
Copy link
Member

karelz commented Sep 27, 2022

Triage: Looks like regression.
WSL 1 wasn't officially supported to our best knowledge, however, we should fix it if it is easy. Not critical for 7.0 though (unless larger number of customers is impacted).

@rzikm
Copy link
Member

rzikm commented Sep 29, 2022

Looks like indeed this is a regression from #63696. I can fix this specific exception for .NET 8 (the PR that broke this changed an exception type which is no longer caught on the problematic code path), but as far as I can see, the NetworkInformation tests could not pass on WSL in the past. For example, calling IPGlobalProperties.GetIPGlobalProperties().GetIPv4GlobalStatistics() fails on my distro because /proc/net/snmp file does not exist in WSL 1.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 29, 2022
@danmoseley
Copy link
Member

@richlander is WSL1 entirely unsupported? I don't believe we test on it, and hit problems in the past.

@karelz karelz added this to the 8.0.0 milestone Sep 29, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 29, 2022
@karelz karelz removed this from the 8.0.0 milestone Sep 29, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 29, 2022
@wfurt
Copy link
Member

wfurt commented Sep 29, 2022

I'm not sure @danmoseley. I would hope we don't break things on old releases. Do you think this can meet servicing bar? (as regression)

@danmoseley
Copy link
Member

danmoseley commented Sep 29, 2022

We have taken fixes for releases we don't support, and even serviced for them - although generally where there is another group doing the maintenance, providing the fix, and doing the testing. I'd imagine if there was a change here for servicing they would ask -- how commonly do customers use WSL1? does this compromise non WSL1 behavior? are we confident that the rest of the product is useful on WSL1 - did you eg run all the unit tests on WSL1? (I'm betting there will be a fair number of failures). If there are other failures that emerge, would we bring fixes for those?

@f-markus can you say more about your customer's usage of WSL1? why do they use it?

@jamshedd @richlander my assumption has been that we broadly support WSL2 in development scenarios, but don't regularly test it off our own dev machines; and we don't support WSL1. Is that correct? Whatever is the case, perhaps it should be clear on https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md.

@karelz
Copy link
Member

karelz commented Sep 29, 2022

Triage: Let's fix what we can easily fix in 8.0.
Based on above answers we can consider backporting to 7.0 if it is supported.

@karelz karelz added this to the 8.0.0 milestone Sep 29, 2022
@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Sep 29, 2022
@danmoseley
Copy link
Member

On my spare box I created a WSL1 Ubuntu, built main and ran tests (incl outerloop). I got 235 failures, most in networking. About 37 hit this bug, the others various things many timeouts, protocol not available... There were other due to other parts of the /proc filesystem being missing or having zeros. Some filesystem failures, a couple where Roslyn code fails in an odd way, a peculiar string parsing one.

It seems it broadly does work (the build worked, for example, and almost all tests are passing) and fixing this issue would fix some, but there are some significant failures too so I'm not sure it's useful for running real apps reliably.

@f-markus
Copy link
Author

f-markus commented Sep 29, 2022 via email

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 30, 2022
@rzikm
Copy link
Member

rzikm commented Sep 30, 2022

Looks like backporting is not necessary, so I will keep the issue closed (it is now fixed in main). If something changes let us know.

@danmoseley
Copy link
Member

danmoseley commented Sep 30, 2022

For what it's worth I reran the tests with this fix. Now there are 198 failures - so it's fixed. But still unclear how useful it is to run code in WSL1. Possibly for some dev scenario, but WSL2 is much preferred.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 31, 2022
@rzikm
Copy link
Member

rzikm commented Jan 25, 2023

Reopening for backporting to 7.0 because the regression was hit in other environments, such as gVisor #81061

@rzikm rzikm reopened this Jan 25, 2023
@karelz karelz modified the milestones: 8.0.0, 7.0.x Jan 31, 2023
@karelz
Copy link
Member

karelz commented Mar 22, 2023

Fixed in main (8.0) in PR #76383 and in 7.0.4 in PR #81157.

@karelz karelz closed this as completed Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants