[release/8.0-staging] [DNS] Ignore ObjectDisposedException on CancellationToken Callback#115841
Merged
liveans merged 4 commits intorelease/8.0-stagingfrom May 27, 2025
Merged
Conversation
…olutionPal.Windows.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
…olutionPal.Windows.cs
karelz
approved these changes
May 22, 2025
Member
karelz
left a comment
There was a problem hiding this comment.
I'd add comment to the @this.DangerousAddRef call that it may throw and it is OK as no-op
Contributor
|
Tagging subscribers to this area: @dotnet/ncl |
antonfirsov
approved these changes
May 22, 2025
Member
|
Approved by @SteveMCarroll via email on 05/27. |
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.
Backport of #115765 to release/8.0-staging
/cc @liveans
Customer Impact
Reported by 2 customers: Customer application crashes due to unhandled
ObjectDisposedExceptionwhen 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