[release/8.0-staging] [DNS] Ignore ObjectDisposedException on CancellationToken Callback #115841
+5
−0
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.
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 in 24h. With the fix we 30h 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