GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Work around runspacepool deadlock by rjmholt · Pull Request #1316 · PowerShell/PSScriptAnalyzer

Conversation

@rjmholt

@rjmholt Rob Holt (rjmholt) commented Aug 21, 2019

Copy link
Copy Markdown
Contributor

PR Summary

Fixes #1297.

Ensures we don't access the CommandInfo.ParameterSets property on PackageManagement cmdlets, which can cause a deadlock for us due to the parallel invocation and they way these cmdlets implement their dynamic parameters.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Rob Holt and others added 4 commits July 30, 2019 10:39
Rob Holt
Add test
9ac1618
Rob Holt
Partial fix
8283030
@rjmholt
Implement workaround for PackageManagement cmdlets
95ad68b
@rjmholt
Fix formatting on test file, add copyright
dd12dd5
@rjmholt
Rob Holt (rjmholt) requested review from James Truher (JamesWTruher), TylerLeonhardt, Christoph Bergmeister (bergmeister) and Dongbo Wang (daxian-dbw) August 21, 2019 16:43
rjmholt
Rob Holt (rjmholt) commented Aug 21, 2019
View reviewed changes
Comment thread Rules/UseCmdletCorrectly.cs
else

// Compares parameter list and mandatory parameter list.
foreach (CommandElementAst commandElementAst in cmdAst.CommandElements.OfType<CommandParameterAst>())

@rjmholt Rob Holt (rjmholt) Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Worth noting that the mandatory parameter logic here is pretty flawed (I haven't changed it from the original). It takes a list of all the mandatory parameters of the cmdlet and checks to see that at least one was supplied.

But:

  • There could be a parameter set specified by a provided non-mandatory parameter which has no mandatory parameters
  • There could be multiple mandatory parameters in a given parameter set

Parameter binding is hard and rather than trying to fix the logic here, any attempt to fix it should be more general-purpose. But nobody seems to have complained about this yet, so I doubt it's actually a huge issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JamesWTruher reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@rjmholt Rob Holt (rjmholt) Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's something I'd like to fix in an external library and reuse in PSSA, PSES and a few other places

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister

Christoph Bergmeister (bergmeister) commented Aug 21, 2019

Copy link
Copy Markdown
Collaborator

Is it possible to have a simpler test case with a less complex file (either instead or additionally)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister

Christoph Bergmeister (bergmeister) commented Aug 21, 2019

Copy link
Copy Markdown
Collaborator

Thinking of the problem on a higher level: We've only discovered that Packagemanagement cmdlet can cause this behaviour. What if more get discovered? It would be good to also have a global setting to disable the runspace pool caching. Is this issue a blocker for a release of a newer version of the vs code ps extension (which would implicitly start to ship with PSSA 1.18.1)? Do we want to have a 1.18.2 release (I would not mind as some useful commits like e.g. actionable error messages for settings files and various formatter fixes/enhancements have gone in already).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister

Christoph Bergmeister (bergmeister) commented Aug 21, 2019

Copy link
Copy Markdown
Collaborator

Please have a look at the build, there is a compilation error when compiling against net452

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt

Rob Holt (rjmholt) commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

Please have a look at the build, there is a compilation error when compiling against net452

Bugger, can't use Array.Empty<T>() after all

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt

Rob Holt (rjmholt) commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

Is this issue a blocker for a release of a newer version of the vs code ps extension (which would implicitly start to ship with PSSA 1.18.1)?

Yes it is. Ideally I'd like to address this issue and area more fully, but for now just trying to unblock.

Is it possible to have a simpler test case with a less complex file (either instead or additionally)?

So far this is the only good repro I've found in PSSA. Even then it's not 100%, but better than nothing.

What if more get discovered?

We've seen this in PSES as well and known about it for some time. It's because PkgMgmt does some extremely unusual threaded things to generate its dynamic parameters. Given that we haven't found any other cases and that this is caused by such a strange implementation, my feeling is thst the right approach is:

  • Hotfix for PackageManagement in PSSA (this can remain in, since old versions of PackageManagement will be out there in use)
  • Fix the issue in PackageManagement (which is more involved, and can't be relied upon to get to everyone)
  • See if the mechanism allowing this to happen can be fixed in PS 7
  • Possibly add more configurability to PSSA
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt
Fix net452 issues
3a9d894
@bergmeister

Christoph Bergmeister (bergmeister) commented Aug 21, 2019

Copy link
Copy Markdown
Collaborator

In the meantime the PSES build could pin 1.18.0 in the call to Save-Module if you want to be able to quicker release an update to the extension before PSSA re-releases?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) approved these changes Aug 21, 2019
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good to me.
Just one question out of curiosity: If not re-using a runspacepool does not cause the problem (if I've read the issue correctly), would it not be simpler to just have an option on GetCommandInfoLegacy to not re-use the runspace pool for the queried command only when the command is one of the Packagemanagement ones?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rjmholt

Rob Holt (rjmholt) commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

If not re-using a runspacepool does not cause the problem (if I've read the issue correctly), would it not be simpler to just have an option on GetCommandInfoLegacy to not re-use the runspace pool for the queried command only when the command is one of the Packagemanagement ones?

I thought about that, but:

  • I feel like using the runspace pool is a legitimate thing to do
  • We want the performance benefit of using it and doing it this way only makes things faster
  • I feel it's uglier to poke a hole in the command info API than to work around the problem at the call site
  • The deadlock itself is complicated enough that I'm not totally convinced that avoiding the runspace pool will totally fix the problem, unlike avoiding the problem path for the PackageManagement cmdlets
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JamesWTruher
James Truher (JamesWTruher) approved these changes Aug 21, 2019
View reviewed changes
Comment thread Rules/UseCmdletCorrectly.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Tests/Engine/DeadlockTestAssets/complex.psm1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt
Add comments to address @JamesWTruher's feedback
8ba2eef
@bergmeister Christoph Bergmeister (bergmeister) mentioned this pull request Aug 24, 2019
Add changelog for 1.18.2 #1323
Merged
2 of 3 tasks
@JamesWTruher

James Truher (JamesWTruher) commented Aug 26, 2019

Copy link
Copy Markdown
Contributor

Christoph Bergmeister (@bergmeister) - I see the signoff for this but I just want to be sure before I merge it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) approved these changes Aug 27, 2019
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

James Truher (@JamesWTruher) I'm still happy with it to be merged, Rob's answer was satisfactory. I don't have any concerns.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JamesWTruher reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@JamesWTruher
James Truher (JamesWTruher) merged commit 3351367 into PowerShell:master Aug 27, 2019
@bergmeister Christoph Bergmeister (bergmeister) mentioned this pull request Jun 17, 2020
PSShouldProcess hangs #1287
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister approved these changes
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
@TylerLeonhardt TylerLeonhardt Awaiting requested review from TylerLeonhardt
+1 more reviewer
@JamesWTruher James Truher (JamesWTruher) JamesWTruher approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Hang (possible deadlock) in PSScriptAnalyzer

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@rjmholt @bergmeister @JamesWTruher
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.