[release/v7.6] Close pipe client handles after creating the child ssh process#26564
Merged
daxian-dbw merged 1 commit intoPowerShell:release/v7.6from Dec 2, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This is a backport of PR #26491 to the release/v7.6 branch, fixing a critical SSH remoting hang on Windows. The core issue was that pipe client handles were not being properly closed after creating the SSH child process, preventing stdout/stderr reader threads from completing when SSH exits. This caused indefinite hangs when using Invoke-Command -HostName or New-PSSession -HostName on Windows.
Key Changes:
- Fixed pipe client handle cleanup by adding
lpStartupInfo.Dispose()to the finally block, ensuring client handles are always closed after process creation - Fixed two critical copy-paste bugs where
stdInWriterVarwas being disposed instead ofstdOutReaderVarandstdErrReaderVar - Added comprehensive tests to verify PowerShell doesn't hang on SSH connections to non-existent hosts
- Refactored namespace references and improved code clarity with modern C# patterns
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/powershell/engine/Remoting/SSHRemotingCmdlets.Tests.ps1 | Adds new tests to verify no hangs occur when connecting to non-existent SSH hosts with both New-PSSession and Invoke-Command |
| src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs | Simplifies namespace references and corrects type alias from FormattedErrorTextWriter to OutOfProcessTextWriter for error prefix checks |
| src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs | Implements the core fix by ensuring pipe client handles are disposed via lpStartupInfo.Dispose() in the finally block; fixes critical disposal bugs; modernizes code with pattern matching and namespace simplifications |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
daxian-dbw
approved these changes
Dec 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport of #26491 to release/v7.6
Triggered by @adityapatwardhan on behalf of @daxian-dbw
Original CL Label: CL-General
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Customer Impact
Fixes critical SSH connection hangs on Windows. When running Invoke-Command -HostName or New-PSSession -HostName on Windows, PowerShell would hang indefinitely due to pipe client handles not being closed after creating the ssh.exe process. This prevents the stdout/stderr reader threads from completing when SSH exits.
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Original PR added tests to verify PowerShell doesn't hang on SSH connections to non-existent hosts. Backport verified by running the new tests on release/v7.6 branch and confirming the fix resolves the Windows-specific SSH hang issue.
Risk
REQUIRED: Check exactly one box.
Medium risk - affects SSH remoting functionality which is commonly used, but the fix is well-scoped to handle cleanup and has comprehensive test coverage. The change only affects the Windows-specific SSH connection code path.