Skip to content

Conversation

@adityapatwardhan
Copy link
Member

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

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

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.

  • Yes
  • No

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.

  • High
  • Medium
  • Low

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.

Copilot AI review requested due to automatic review settings December 2, 2025 23:28
@adityapatwardhan adityapatwardhan added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Dec 2, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 stdInWriterVar was being disposed instead of stdOutReaderVar and stdErrReaderVar
  • 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 daxian-dbw merged commit 2e04792 into PowerShell:release/v7.6 Dec 2, 2025
40 checks passed
@adityapatwardhan adityapatwardhan deleted the backport/release/v7.6/26491-9ee3c61c2 branch December 3, 2025 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants