Skip to content

Fix NotSupportedException in DnsSocket.ReceiveAsync peek overload on macOS - #134924

Merged
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:osx-dns-fix
Sep 30, 2026
Merged

rzikm merged 1 commit into
dotnet:mainfrom
rzikm:osx-dns-fix

Conversation

@rzikm

@rzikm rzikm commented Sep 30, 2026

Copy link
Copy Markdown
Member

Description

The macOS DnsResolver implementation (DnsResolverPal.OSX.cs) awaits readiness on the mDNSResponder connection's socket file descriptor by calling DnsSocket.ReceiveAsync(buffer, peek: true, cancellationToken). That overload forwards to Socket.ReceiveAsync(Memory<byte>, SocketFlags, CancellationToken) via an [UnsafeAccessor]-decorated method whose flags parameter was typed with [UnsafeAccessorType("System.Net.Sockets.SocketFlags, System.Net.Sockets")].

UnsafeAccessorType cannot represent value types (see the existing comment/workaround already applied to the Socket constructor's SocketType/ProtocolType enum parameters in the same file). Because SocketFlags is an enum, this threw System.NotSupportedException: ValueTypes are not supported with UnsafeAccessorTypeAttribute at runtime on every call — breaking every async DNS query path on macOS.

This was visible in CI as widespread System.Net.NameResolution.Functional.Tests failures on macOS outer-loop runs, e.g.:

System.NotSupportedException : ValueTypes are not supported with UnsafeAccessorTypeAttribute.
   at System.Net.DnsSocket.ReceiveAsync(Object socket, Memory`1 buffer, Object flags, CancellationToken cancellationToken)

Fix

Apply the same reflection-based workaround already used for the Socket constructor: cache a MethodInfo for the SocketFlags-taking ReceiveAsync overload and invoke it via MethodInfo.Invoke, instead of declaring it through [UnsafeAccessor]/[UnsafeAccessorType].

Testing

Ran the full macOS outer-loop System.Net.NameResolution.Functional.Tests suite (DnsResolverTest, sync and async variants) locally on macOS/arm64:

=== TEST EXECUTION SUMMARY ===
   System.Net.NameResolution.Functional.Tests  Total: 38, Errors: 0, Failed: 0, Skipped: 1

Prior to the fix, every async test case failed with the NotSupportedException above.

Note

This PR description and commit were AI-generated with GitHub Copilot CLI.

…macOS

UnsafeAccessorType cannot represent value-type parameters, but the
SocketFlags-taking ReceiveAsync overload declared its flags parameter
with [UnsafeAccessorType], which threw NotSupportedException at
runtime and broke every async DNS query on macOS (the OSX resolver
uses this overload to await readiness on the mDNSResponder socket
fd). Invoke that overload via reflection instead, mirroring the
existing workaround used for the Socket constructor's value-type enum
parameters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
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.

@rzikm

rzikm commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

/azp run runtime-libraries-coreclr outerloop

@rzikm
rzikm requested a review from a team September 30, 2026 11:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@rzikm
rzikm enabled auto-merge (squash) September 30, 2026 13:09
@rzikm
rzikm merged commit 77595b4 into dotnet:main Sep 30, 2026
94 of 96 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants