Repository navigation
Close pipe client handles after creating the child ssh process - #26491
Merged
Travis Plunk (TravisEz13) merged 7 commits intoNov 24, 2025
Merged
Conversation
Dongbo Wang (daxian-dbw)
requested a review
from Travis Plunk (TravisEz13)
as a code owner
November 19, 2025 22:13
Dongbo Wang (daxian-dbw)
marked this pull request as draft
November 20, 2025 05:45
…ted by the child process
Dongbo Wang (daxian-dbw)
marked this pull request as ready for review
November 20, 2025 19:27
Ilya (iSazonov)
approved these changes
Nov 21, 2025
Member
Author
|
Good point. Actually, disposing |
Ilya (iSazonov)
approved these changes
Nov 22, 2025
Collaborator
|
I believe we need to backport the commit. |
Travis Plunk (TravisEz13)
approved these changes
Nov 24, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Travis Plunk (TravisEz13)
approved these changes
Nov 24, 2025
Travis Plunk (TravisEz13)
enabled auto-merge (squash)
November 24, 2025 19:52
Aditya Patwardhan (adityapatwardhan)
pushed a commit
to adityapatwardhan/PowerShell
that referenced
this pull request
Dec 2, 2025
3 of 9 tasks
SIRMARGIN
pushed a commit
to SIRMARGIN/PowerShell
that referenced
this pull request
Dec 12, 2025
Ryan Yates (kilasuit)
pushed a commit
to kilasuit/PowerShell
that referenced
this pull request
Jan 2, 2026
Dongbo Wang (daxian-dbw)
added a commit
to daxian-dbw/PowerShell
that referenced
this pull request
Feb 13, 2026
3 of 9 tasks
Aditya Patwardhan (adityapatwardhan)
pushed a commit
to adityapatwardhan/PowerShell
that referenced
this pull request
Apr 1, 2026
3 of 9 tasks
Justin Grote (JustinGrote)
pushed a commit
to JustinGrote/PowerShell
that referenced
this pull request
Jun 2, 2026
Thatgfsj (Thatgfsj)
pushed a commit
to Thatgfsj-contribs/PowerShell
that referenced
this pull request
Aug 6, 2026
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.
PR Summary
Fix #25203
Fix #26228
Symptom
Running the following commands on Windows will hang indefinitely today.
Invoke-Command -HostName "test" -UserName "test" -ScriptBlock { 1 }New-PSSession -HostName "test" -UserName "test"The reported hang happens on Windows only. On Linux and macOS, both commands return to the prompt with an error written out.
Root Cause
What happens on Windows is -- the
ssh.exeprocess already exited, but thestdinwriter andstdout/stderrreaders were not closed as expected. That led to the hang, as both the output and error reader threads were still blocked on thereader.ReadLinecall.This is because when creating the
ssh.exeusing the Win32 functionCreateProcess, we don't close the client handles of the pipes (stdInPipeClient,stdOutPipeClient, andstdErrPipeClient) after they get inherited by the child process (see code).When inherited by a child process, the parent side of those handles remain valid and unchanged. Windows duplicates that handle into the child process's handle table.
So, when the child process
ssh.exeexits, the pipe client handles in the child process are automatically closed. However, the pipe client handles in the parent processpowershellare still open, so the pipes will remain functional and thus the pipe server handles (i.e. the readers used in the stdout/stderr reading threads) are still open. Therefore, the hang happens.Fix Changes
To fix the issue, we need to close the parent side pipe client handles right after creating the
ssh.exeprocess, so, only thessh.exeprocess holds the handles of client side of the pipes. Then later, whenssh.exeexits, the client side of the pipe will be closed, which will, as expected, lead the server side of the pipes to be closed too.The main changes of the fix are:
lpStartupInfo.Dispose()in the finally block).System.Diagnostics.Process,System.IO.Path, etc.)PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header