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

DnsAddresses throw PlatformNotSupportedException if /etc/resolv.conf is missing #109582

Open
Emdot opened this issue Nov 6, 2024 · 3 comments
Open
Labels
area-System.Net bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@Emdot
Copy link

Emdot commented Nov 6, 2024

Description

On Linux, IPInterfaceProperties.DnsAddresses throws PlatformNotSupportedException if /etc/resolv.conf is missing. This is incorrect. Per the man page, if the file does not exist (or has no nameserver lines) then the host acts as its own name server.

Reproduction Steps

On a Linux machine:

mv /etc/resolv.conf /etc/resolv.conf.backup
dotnet new console -o dnstest
cd dnstest
echo "using System.Net.NetworkInformation; Console.WriteLine(string.Join(' ', NetworkInterface.GetAllNetworkInterfaces().SelectMany(nic => nic.GetIPProperties().DnsAddresses)));" > Program.cs
dotnet run

Expected behavior

127.0.0.1 or 127.0.0.1 ::1

Alternately, blank might be considered correct depending on how you define the DnsAddresses property. That would be consistent with the case where /etc/resolv.conf has no nameserver lines, which presently produces an empty list. Or perhaps it should depend on whether the host actually has a DNS service running.

Alternately, document that PlatformNotSupportedException can be thrown if the DNS configuration is missing. Although I think InvalidOperationException is a better choice, since it's not really a platform-specific problem.

Regardless, the behavior when the file is missing should match the behavior when the file is empty.

Actual behavior

Unhandled exception. System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
   at System.Net.NetworkInformation.UnixIPInterfaceProperties.get_DnsAddresses()
   at Program.<>c.<<Main>$>b__0_0(NetworkInterface nic) in /home/mmorrison/dnstest/Program.cs:line 1
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.String.JoinCore[T](ReadOnlySpan`1 separator, IEnumerable`1 values)
   at System.String.Join[T](Char separator, IEnumerable`1 values)
   at Program.<Main>$(String[] args) in /home/mmorrison/dnstest/Program.cs:line 1

Regression?

No response

Known Workarounds

Catch the exception and treat it as an empty list.

Configuration

dotnet 6.0.135
Red Hat Enterprise Linux 8.10
x64
based on source code, the issue should apply to all Linux hosts

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 6, 2024
Copy link
Contributor

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

@antonfirsov antonfirsov added the bug label Nov 6, 2024
@antonfirsov antonfirsov added this to the Future milestone Nov 6, 2024
@antonfirsov antonfirsov added help wanted [up-for-grabs] Good issue for external contributors and removed untriaged New issue has not been triaged by the area owner labels Nov 6, 2024
@antonfirsov
Copy link
Member

antonfirsov commented Nov 6, 2024

I think this is worth to fix, and also looks like a good candidate for community contribution. @wfurt do you agree? Any thoughts re returning 127.0.0.1 vs empty list?

@wfurt
Copy link
Member

wfurt commented Nov 6, 2024

either way. I feel we should not throw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Net bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

3 participants