-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make PowerShell class not affiliate with Runspace when declaring the NoRunspaceAffinity attribute
#18138
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
Conversation
…unspaceAffinity` attribute
PaulHigin
left a comment
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.
Changes look good except for test typo. Please create a document issue for this new attribute, that will describe what it does and possible consequences for using it.
|
Thanks @PaulHigin, the doc issue was opened: MicrosoftDocs/PowerShell-Docs#9231. |
iSazonov
left a comment
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.
LGTM with one minor question.
SeeminglyScience
left a comment
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.
LGTM! This adds a very clean option here ❤️ love it
One very skippable suggestion
test/powershell/Language/Classes/Scripting.Classes.NoRunspaceAffinity.Tests.ps1
Outdated
Show resolved
Hide resolved
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
PR Summary
Fix #12801
Make PowerShell class not affiliate with Runspace when declaring the
NoRunspaceAffinityattribute.By default, a PowerShell class is affiliated with the Runspace where it's created. This makes it not work in a parallel workflow, such as
ForEach-Object -Parallel-- method invocations on the class would be marshalled back to the Runspace it was created, which could cause corruption to the state of that Runsapce or a deadlock. See #4003 and #3651 for examples.With this PR, if the attribute
NoRunspaceAffinityis declared for a PowerShell class, then the PowerShell class will not be affiliated with a particular Runspace/SessionState, and its method invocation (both instance and static) will use the default Runspace of the running thread and its current session state.Of course, once declaring the attribute to the class, the class implementation should not depend on any states of a particular session state, because there is no guarantee the dependencies would be available at runtime.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.NoRunspaceAffinityattribute introduced to PowerShell class MicrosoftDocs/PowerShell-Docs#9231