GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — Give each runspace in a `RunspacePool` its own `InitialSessionState` by ryanriesMSFT · Pull Request #28286 · PowerShell/PowerShell ConversationPR SummaryGive each runspace in a local Sharing the instance can make a pooled runspace silently skip a module's type and format data ( Changes:
PR Context
Each runspace still has its own
When B then imports the same module, the files are already listed, so B never loads them. Member lookup falls back to the CIM/.NET adapter and returns the raw value. No error or warning is written. The problem is intermittent and only shows up in some hosts because it requires all of the following:
Code paths that create standalone runspaces already clone the Not sharing the instance also removes other cross-runspace effects of the shared object:
Cost: one Windows repro. Without the fix, the second line typically shows $pool = [runspacefactory]::CreateRunspacePool(1, 2) $pool.Open() $script = { param($delay) Start-Sleep -Seconds $delay # the first command imports NetConnection at ~2s, the second at ~4s $p = Get-NetConnectionProfile | Select-Object -First 1 Start-Sleep -Seconds (6 - $delay) # keep the first runspace busy so the pool opens a second one up front '{0}: {1} ({2})' -f [runspace]::DefaultRunspace.Name, $p.NetworkCategory, $p.NetworkCategory.GetType().Name } $invocations = 2, 4 | ForEach-Object { $ps = [powershell]::Create().AddScript($script).AddArgument($_) $ps.RunspacePool = $pool [pscustomobject]@{ PowerShell = $ps; Handle = $ps.BeginInvoke() } } $invocations | ForEach-Object { $_.PowerShell.EndInvoke($_.Handle) } $pool.Dispose() The new cross-platform test reproduces the same ordering deterministically with a self-contained module that has a types file and a format file. It uses events instead of sleeps. Results:
Locally, I also ran the existing tests that use runspace pools, along with the PR Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. RunspacePoolInternal created every runspace with CreateRunspaceFromSessionStateNoClone, so all runspaces in a pool shared a single InitialSessionState instance. The InitialSessionState is updated when a runspace is opened and when modules are imported into it (for example, the type and format files that were loaded are recorded in its Types and Formats collections), and Import-Module uses those collections to decide whether a module's TypesToProcess and FormatsToProcess files are already loaded. As a result, a runspace that was opened before another runspace in the same pool imported a module skipped that module's type and format data when it imported the module itself. ETS members such as the enum script properties generated for CDXML modules (NetConnection, Storage, ...) were missing in that runspace, so properties like NetworkCategory surfaced as raw integers. Whether a given runspace was affected depended on runspace creation order and timing. Create pooled runspaces with RunspaceFactory.CreateRunspace, which clones the pool's InitialSessionState exactly like a standalone runspace, and remove the now-unused no-clone code path. Co-authored-by: Copilot <[email protected]> Copilot-Session: 7411f14d-b619-4f89-9a9e-b0880f11ef33
Joseph "Ryan" Ries (ryanriesMSFT)
force-pushed
the
fix-runspacepool-per-runspace-iss
branch
from
94e152f to
b3a7e4b
Compare
Joseph "Ryan" Ries (ryanriesMSFT)
marked this pull request as ready for review
Joseph "Ryan" Ries (ryanriesMSFT)
requested a review
from a team
as a code owner
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Approval recommendedNo active review issues were identified for the change isolating each pooled runspace’s session state. No open issues 🎉 What changed in this PRThis PR isolates each local pooled runspace’s Changes:
Review effort: Balanced
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reviewers
Copilot code review
Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
At least 1 approving review is required to merge this pull request. Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
Review - Needed
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. |