[release/8.0-staging] [DNS] Ignore ObjectDisposedException on CancellationToken Callback by github-actions[bot] · Pull Request #115841 · dotnet/runtime
Backport of #115765 to release/8.0-staging
/cc @liveans
Customer Impact
Reported by 2 customers: Customer application crashes due to unhandled ObjectDisposedException when they call DNS APIs (e.g. Dns.GetHostAddress) and then start cancellation of the request (e.g. when the DNS response takes long time due to network environment).
Technical details: There’s a race condition between the DNS request completion and the CancellationToken-registered callback in our code.
We're currently checking whether the DNS request has completed before initiating the cancellation process, but it's possible for the DNS request to complete right after the check. That can lead to the ObjectDisposedException, because we assume the DNS request is still valid, while it was completed in the meantime.
Regression
Yes, introduced in #63904 (part of .NET 7.0).
Testing
Verified on targeted stress test - without the change in fails 3x in 24h. With the fix 30 h & ~70h without a crash.
Risk
Low, fix is targeted to a specific case.
Package authoring no longer needed in .NET 9
N/A - this is not a NuGet package, just part of runtime itself