Memory+Thread leak when using WinPSCompatSession and RunspacePool #17473
Labels
Needs-Triage
The issue is new and needs to be triaged by a work group.
WG-Engine-Module
WG-Engine-Performance
core PowerShell engine, interpreter, and runtime performance


Prerequisites
Steps to reproduce
When running WindowsPowerShell-only cmdlets via WinPSCompat implicit and leveraging a RunspacePool (runspaces running in parallel), memory leaks + thread leaks will occur.
Consider the following snippet:
Items to consider:
ForEach-Object -Parallelinternally uses a runspace pool to orchestrate requests across multiple runspaces in parallel; This issue is also reproducible when aRunspacePoolis used directly withPowerShellobjects to run script blocks.Get-WMIObjectis a WindowsPowerShell-only cmdlet, so its invocation will use the Windows PowerShell compatibility (WinPSCompat session) implicitly.Expected behavior
No memory leaks or thread leaks occur: PowerShell 7 is able to handle the implicit creation + disposal of the WinPSCompat session and corresponding remoteIpMoProxy_* stub modules automatically.
Actual behavior
On the PowerShell script share above, Memory leaks + thread leaks occur:
OutOfProcessClientSessionTransportManagerBase.ProcessMessageProc())Error details
No response
Environment data
Visuals
Folders remoteIpMoProxy_* keep being added but not deleted.

Theads and overall memory of the Pwsh.exe process keeps increasing as the above script runs. This is a snapshot after running for just a few minutes:

The text was updated successfully, but these errors were encountered: