Repository navigation
Treat a missing /etc like a missing /etc/resolv.conf in NetworkInformation - #135569
Merged
Merged
Conversation
…ation When /etc does not exist, reading /etc/resolv.conf throws DirectoryNotFoundException rather than FileNotFoundException, because ENOENT with a missing parent directory is mapped to DirectoryNotFoundException. The resolv.conf readers only caught FileNotFoundException, so NetworkInterface.GetAllNetworkInterfaces() threw on Linux. The readers used by the BSD and Apple IPInterfaceProperties had the same catch. Move the read into a shared StringParsingHelpers.ReadResolvConfFile helper that returns null for both FileNotFoundException and DirectoryNotFoundException, and use it from all three readers. A missing /etc now yields no DNS information, as a missing resolv.conf already did. The Linux reader still also ignores UnauthorizedAccessException, as before. Fix dotnet#135568 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
MihaZupan
reviewed
Oct 12, 2026
Only the Linux reader ignored UnauthorizedAccessException from /etc/resolv.conf; the BSD and Apple readers let it escape. Handle it in the shared helper so all three readers treat an unreadable resolv.conf like a missing one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MihaZupan
approved these changes
Oct 12, 2026
MihaZupan
left a comment
Member
There was a problem hiding this comment.
This seems reasonable to me, thank you
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation correctly addresses the reported failure with appropriate cross-platform consistency and regression coverage.
0 open findings
What changed in this PR
Fixes NetworkInterface.GetAllNetworkInterfaces() when /etc or resolv.conf is unavailable by centralizing resilient resolver configuration reads.
Changes:
- Handles missing directories, missing files, and denied access consistently.
- Updates Linux, BSD, and Apple call paths.
- Adds regression coverage for unavailable resolver configuration.
| File | Description |
|---|---|
DnsParsingTests.cs |
Tests missing and inaccessible resolver configuration. |
UnixIPInterfaceProperties.cs |
Uses the shared resolver reader. |
StringParsingHelpers.Dns.cs |
Adds the resilient file-reading helper. |
LinuxNetworkInterface.cs |
Uses the helper for Linux DNS properties. |
🧠 Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux,
NetworkInterface.GetAllNetworkInterfaces()throwsSystem.IO.DirectoryNotFoundExceptionwhen/etcdoes not exist./etc/resolv.confis read withFile.ReadAllText, which mapsENOENTtoDirectoryNotFoundExceptionwhen the parent directory is missing, and the reader catches onlyFileNotFoundExceptionandUnauthorizedAccessException. The two/etc/resolv.confreaders inUnixIPInterfaceProperties, used by the BSD and Apple implementations, catch onlyFileNotFoundException.The read now goes through one internal helper,
StringParsingHelpers.ReadResolvConfFile, which returnsnullforFileNotFoundException,DirectoryNotFoundExceptionandUnauthorizedAccessException. All three readers use it, so a missing/etcgives no DNS information, as a missing/etc/resolv.confalready did.UnauthorizedAccessExceptionwas ignored only by the Linux reader; the BSD/Apple readers now ignore it too. No public API change.Tests: a new theory in
DnsParsingTestschecks that the helper returnsnullfor a missing file and for a file under a missing directory; with the helper's catch narrowed toFileNotFoundException(a Windows run), the directory case fails withDirectoryNotFoundException. A new fact checks that the helper returnsnullwhen given a directory; withUnauthorizedAccessExceptionremoved from the helper's catch, it fails with that exception (a Windows run). The existing resolv.conf parsing tests now read their input through the helper. The System.Net.NetworkInformation functional tests passed on Windows; on Linux all passed exceptIPGlobalProperties_DomainName_ReturnsEmptyStringWhenNotSet, which fails with and without this change on the test machine (DomainNamereturns"localdomain"there). The repro from the issue passed with the fix, both with no/etcand with an/etcthat has noresolv.conf. The BSD and Apple implementations were compiled but not run.Resolves #135568
Note
AI-generated, written at my direction and reviewed by me before posting. Verified on dotnet/runtime 9bfbe1d with the first commit of this change applied. On Ubuntu 22.04.5 LTS x64 on WSL2 (Linux 6.18.40.1), after
./build.sh clr+libs -rc Release, with./.dotnet/dotnet build src/libraries/System.Net.NetworkInformation/src,./.dotnet/dotnet build src/libraries/System.Net.NetworkInformation/tests/FunctionalTests /t:Test, and the issue's repro commands run as root (dotnet build -c Release -o outwith the repo's SDK, then./run.sh "$(command -v dotnet)" out/repro.dllwithartifacts/bin/testhost/net11.0-linux-Debug-x64first onPATH). On Windows x64, afterbuild.cmd clr+libs -rc checked, withdotnet.cmd build src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj /p:TargetOS=<os>forlinux,freebsdandosx(each built every target framework of the library) and the functional tests via/t:Test; the new theory was also run with the helper's catch narrowed toFileNotFoundException, where itsetc/resolv.confcase failed withDirectoryNotFoundException. These runs predate the review commit that moved theUnauthorizedAccessExceptioncatch into the helper; that commit was built on Windows for every target framework of the library, and the functional tests passed on Windows.