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

Fix lock up that occurs when WinForms is executed on the pipeline thread #1149

Merged
merged 5 commits into from
Jan 9, 2020

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Jan 8, 2020

Fixes PowerShell/vscode-powershell#2352.

Dequeuing work to execute on the pipeline thread used to be async/await without using ConfigureAwait(false). This meant that introducing a thread synchronisation context (like WinForms does) could break our thread architecture.

Particularly in the WinForms case, the work dequeuing delegate would be marshalled back to the pipeline thread, which was blocked by the stopped debugger, so unable to execute.

Now we use ConfigureAwait(false) so that the lock delegate's execution is not influenced by the synchronisation context.

@rjmholt rjmholt changed the title Improve lock up that occurs when WinForms is executed on the pipeline thread [WIP] Improve lock up that occurs when WinForms is executed on the pipeline thread Jan 8, 2020
@rjmholt rjmholt changed the title [WIP] Improve lock up that occurs when WinForms is executed on the pipeline thread Fix lock up that occurs when WinForms is executed on the pipeline thread Jan 8, 2020
this.logger.LogTrace(
"Attempting to get session details failed, most likely due to a running pipeline that is attempting to stop.");
}
// Get the session details and push the current
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic change to fix misleading indentation

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

There's going to be a lot of this littered throughout the code base. We used to have a custom sync context that required us to be more selective about how we configured awaits. Now that we don't have that, we might want to:

  1. Set up the analyzer that warns when ConfigureAwait(false) isn't present
  2. Configure every single await 🙂. It won't look great, but it'll save us a few out of no where deadlocks

src/PowerShellEditorServices/Server/PsesDebugServer.cs Outdated Show resolved Hide resolved
Co-Authored-By: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
@TylerLeonhardt
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 3
- Added 1
           

See the complete overview on Codacy

/// <summary>
/// This is a bool but must be an int, since Interlocked.Exchange can't handle a bool
/// </summary>
private static int s_hasRunPsrlStaticCtor = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyleejordan
Copy link
Member

LGTM!

There's going to be a lot of this littered throughout the code base. We used to have a custom sync context that required us to be more selective about how we configured awaits. Now that we don't have that, we might want to:

  1. Set up the analyzer that warns when ConfigureAwait(false) isn't present
  2. Configure every single await 🙂. It won't look great, but it'll save us a few out of no where deadlocks

LMAO we finally got around to this, and I did for the OmniSharp library too.

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

Successfully merging this pull request may close these issues.

Creating Windows.Forms.Form lock the debugger - v2019.11.0-preview
4 participants