Repository navigation
Conversation
sean-mcmanus
commented
Sep 1, 2026
Contributor
Author
|
@dotnet-policy-service agree company="Microsoft" |
nkolev92
reviewed
Sep 1, 2026
lifengl
approved these changes
Sep 2, 2026
lifengl
left a comment
Contributor
There was a problem hiding this comment.
This PR is valid, and potentially addresses some narrow deadlock chances. Although it has no effect on the deadlock VC team ran into.
Contributor
|
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
Contributor
Author
|
@dotnet-bot I'm registering activity? |
nkolev92
approved these changes
Sep 10, 2026
This was referenced Sep 16, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
Fixes: NuGet/Home#8248
Related: NuGet/Home#9447
Related: #7676
Description
HttpHandlerResourceV3.CredentialServiceis exposed as a synchronousLazy<ICredentialService>, but its deferred factory performs asynchronous Visual Studio work. When a background caller owns the outerLazy<T>monitor while that work needs the UI thread, a UI-thread caller can block on the monitor before it has an opportunity to join the in-flight JTF operation.This change preserves deferred initialization and the existing
Lazy<ICredentialService>contract while moving the asynchronous work into one JTF-backedAsyncLazy<ICredentialService>. The compatibilityLazy<T>usesLazyThreadSafetyMode.PublicationOnly, allowing concurrent callers to reach and join the same inner task instead of serializing on the outer monitor. The helper also asserts that a JTF is present rather than silently constructing a non-joinableAsyncLazy<T>. The now-obsoleteVSTHRD011suppression is removed.Because the public protocol surface remains synchronous, callers still block while
AsyncLazy<T>.GetValue()joins the inner operation. Eliminating that blocking and addressing resolver paths with no shared JTF context would require a new cancellation-aware asynchronous credential API and migration of the protocol consumers; that broader design is outside this fix.NuGet/Home#8248 was closed by stale cleanup without a fixing pull request and has since been reopened. NuGet/Home#9447 tracks the broader SDK-resolver authentication scenario; this change addresses the credential-initialization edge but does not claim to resolve every resolver scheduling path. NuGet.Client#7676 independently removes one obsolete UI-thread dependency from credential setup.
Testing
Added a deterministic Windows .NET Framework regression test that:
The unchanged test was run against both implementations:
The main thread deadlocked waiting for credential service initialization.The normally signed
NuGet.PackageManagement.VisualStudioproduction project also built successfully with threading analyzers enabled, includingVSTHRD011. All current-head pull-request checks passed. A patched VSIX was not manually launched against a full Visual Studio solution; the regression test directly and deterministically exercises the background-initialization/UI-caller cycle addressed by this change.PR Checklist