Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Package Manager Console initialization might cause deadlocks #11320

Closed
zivkan opened this issue Oct 19, 2021 · 0 comments · Fixed by NuGet/NuGet.Client#4317
Closed

[Bug]: Package Manager Console initialization might cause deadlocks #11320

zivkan opened this issue Oct 19, 2021 · 0 comments · Fixed by NuGet/NuGet.Client#4317

Comments

@zivkan
Copy link
Member

zivkan commented Oct 19, 2021

NuGet Product Used

Visual Studio Package Manager Console

Product Version

all?

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

There's a timing bug, which means that it can't be reproduced on demand, it just depends if everything lines up in the wrong way.

Huge thanks to @sharwell and @CyrusNajmabadi for finding and telling us about the problem (and how to fix

Low level details are:

During PMC initialization, RunspaceManager.CreateRunspace casts a DTE object to DTE2, but at this time it's running on a background thread. Since DTE(2) is a COM object, it needs the UI thread to do the cast.

However, if something is blocking the UI thread, NuGet/PMC can't get the UI thread to do the cast. If the code blocking the UI thread called a NuGet API and is waiting for the result, this causes a deadlock.

A few lines earlier in RunspaceManager.cs, PMC gets the DTE object via NuGet's ServiceLocator, which correctly uses JTF to switch to the UI thread. Hence, by getting the service locator to cast to DTE2, rather than doing it from a background thread, this should eliminate the risk of deadlock.

Verbose Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant