Skip to content

package initialization can cause deadlock #243

Open
@zivkan

Description

@zivkan

Describe the bug
This is the root cause of https://developercommunity.visualstudio.com/t/Visual-Studio-freeze-with-message-Loadi/10730260

There are multiple contributing factors, such as an action in VS causing the markdown editor to load even though it's not needed, and the VS SDK not using the vs-threading analyzer to warn about an API that should be called on the UI thread.

in the package init code:

RegisterEditorFactory(editorFactory);
await JoinableTaskFactory.SwitchToMainThreadAsync();

RegisterEditorFactory is being called before switching to the UI thread. However, it turns out that RegisterEditorFactory calls a COM object, and therefore the UI thread is needed. However, COM isn't JTF aware, hence the deadlock if the UI thread is being blocked until the package load is complete. These two lines should be switched, so the method is called on the UI thread.

To Reproduce
Steps to reproduce the behavior:

  1. Open a markdown file, but then switch to a different editor, so the markdown editor is in the background.
  2. Close VS
  3. Open a new VS instance, and open the same solution.
  4. Right click the solution and choose Manage NuGet Packages.

Expected behavior
NuGet's package manager opens

Screenshots
I don't want to share another customer's screenshot, but VS has a dialog saying "opening document", that never goes away, and the main VS window becomes "not responding"

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions