GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix SSH remoting connection hang with misconfigured endpoint by PaulHigin · Pull Request #15175 · PowerShell/PowerShell

Conversation

@PaulHigin

@PaulHigin Paul Higinbotham (PaulHigin) commented Apr 6, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

This fixes the SSH remoting hang issue: #15174

PR Context

If an SSH remoting endpoint configuration (sshd_config file) is misconfigured, the ssh.exe client process used to make the ssh connection fails silently. No error is emitted. As a result, the PowerShell remoting layer waits indefinitely for protocol messages.

I also noticed that the base transport manager message queue threads were not being cleaned up in this case, because a connection is never established and the normal protocol close processing never occurs. So I have modified the code to ensure this clean up is done in this SSH connection failed case.

After some discussion, the proposed fix is to add a -ConnectingTimeout parameter to SSH remoting that abandons a connection attempt after the timeout period. The default value will be infinite so as not to introduce regressions.

This change will affect:

Enter-PSSession SSH parameter set
Invoke-PSSession SSH parameter set
New-PSSession SSH parameter set
SSHConnectionInfo class

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: or [ WIP ] to the beginning of the title (the WIP bot will keep its status check at Pending while the prefix is present) and remove the prefix when the PR is ready.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed: Add documentation for new -ConnectingTimeout parameter for SSH remoting MicrosoftDocs/PowerShell-Docs#7464
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    • OR
    • I have considered the user experience from a tooling perspective and opened an issue in the relevant tool repository. This may include:
      • Impact on PowerShell Editor Services which is used in the PowerShell extension for VSCode
        (which runs in a different PS Host).
        • Issue filed:
      • Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
        • Issue filed:
      • Impact on PSScriptAnalyzer (which provides linting & formatting in the editor extensions).
        • Issue filed:
      • Impact on EditorSyntax (which provides syntax highlighting with in VSCode, GitHub, and many other editors).
        • Issue filed:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@PaulHigin
Fix SSH remoting connection hang with misconfigured endpoint
f9cb740
@ghost ghost assigned Dongbo Wang (daxian-dbw) Apr 6, 2021
@PaulHigin
Paul Higinbotham (PaulHigin) requested review from James Truher (JamesWTruher), Anam Navied (anamnavi) and Ilya (iSazonov) April 6, 2021 19:47
JamesWTruher
James Truher (JamesWTruher) reviewed Apr 6, 2021
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin
Paul Higinbotham (PaulHigin) requested a review from James Truher (JamesWTruher) April 6, 2021 22:21
JamesWTruher
James Truher (JamesWTruher) approved these changes Apr 7, 2021
View reviewed changes
@PaulHigin Paul Higinbotham (PaulHigin) changed the title Fix SSH remoting connection hang with misconfigured endpoint [WIP] Fix SSH remoting connection hang with misconfigured endpoint Apr 7, 2021
@PaulHigin Paul Higinbotham (PaulHigin) added WG-Remoting PSRP issues with any transport layer Needs-Triage The issue is new and needs to be triaged by a work group. labels Apr 7, 2021
@PaulHigin

Paul Higinbotham (PaulHigin) commented Apr 7, 2021

Copy link
Copy Markdown
Contributor Author

Remoting working group: Please see solution proposal in PR Context section.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TravisEz13

Travis Plunk (TravisEz13) commented Apr 7, 2021

Copy link
Copy Markdown
Member

Remoting working group: The proposed fix to add a -ConnectingTimeout parameter to SSH remoting that abandons a connection attempt after the timeout period. The default value will be infinite so it is not a breaking change.

This seems like a good fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Paul Higinbotham (PaulHigin) added 7 commits April 9, 2021 11:07
@PaulHigin
Add support for SSH connection attempt timeout
25a3ac7
@PaulHigin
Fix CodeFactor issues
bf1a6a8
@PaulHigin
Add Write-Verbose for debugging
95c9942
@PaulHigin
Add more debug info
a4c521e
@PaulHigin
[Feature]
50dc464
@PaulHigin
More debug output
853598c
@PaulHigin
[Feature]
33f5e50
iSazonov
Ilya (iSazonov) reviewed Apr 10, 2021
View reviewed changes
Comment thread test/SSHRemoting/SSHRemoting.Basic.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Paul Higinbotham (PaulHigin) added 9 commits April 12, 2021 09:18
@PaulHigin
Ensure all It blocks have Should
64af989
@PaulHigin
Try removing AfterEach
d05e51a
@PaulHigin
[Feature]
3332b2f
@PaulHigin
[Feature]
3d82ad6
@PaulHigin
Debug1
0079c52
@PaulHigin
Debug2
a770916
@PaulHigin
Debug3
9b51d70
@PaulHigin
Debug4
3a47c80
@PaulHigin
Debug5
70dfcd4
Paul Higinbotham (PaulHigin) added 2 commits April 12, 2021 14:48
@PaulHigin
Final change
0dfde2b
@PaulHigin
Modify close logic to catch specific exceptions
430b3a2
@PaulHigin Paul Higinbotham (PaulHigin) changed the title [WIP] Fix SSH remoting connection hang with misconfigured endpoint Fix SSH remoting connection hang with misconfigured endpoint Apr 12, 2021
@PaulHigin

Paul Higinbotham (PaulHigin) commented Apr 12, 2021

Copy link
Copy Markdown
Contributor Author

After some experimentation, it appears the random hang is during the connection close process, if the target is no longer responding. The base transport manager already has code to handle this with a try/catch around the text writer object that sends the PSRP message. However, the catch didn't include 'ObjectDisposedException' and after adding this in the handler, the hang appears to have gone away.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Apr 13, 2021
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/SSHRemoting/SSHRemoting.Basic.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin
Implement review comments
922962d
iSazonov
Ilya (iSazonov) reviewed Apr 13, 2021
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/commands/PSRemotingCmdlet.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin Paul Higinbotham (PaulHigin) mentioned this pull request Apr 13, 2021
Add documentation for new -ConnectingTimeout parameter for SSH remoting MicrosoftDocs/PowerShell-Docs#7464
Closed
@PaulHigin
Resolve more comment change requests
bd137f2
iSazonov
Ilya (iSazonov) approved these changes Apr 13, 2021
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Magic! :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

PaulHigin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 13, 2021
@PaulHigin
Previously neglected to commit test change
082b50a
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 046e0fe into PowerShell:master Apr 13, 2021
@daxian-dbw Dongbo Wang (daxian-dbw) removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Apr 13, 2021
@daxian-dbw Dongbo Wang (daxian-dbw) added this to the 7.2.0-preview.5 milestone Apr 13, 2021
@ghost

Deleted user (ghost) commented Apr 14, 2021

Copy link
Copy Markdown

🎉v7.2.0-preview.5 has been released which incorporates this pull request.:tada:

Handy links:

  • Release Notes
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Travis Plunk (TravisEz13) added a commit that referenced this pull request Apr 16, 2021
@TravisEz13
Merge tag 'v7.2.0-preview.5'
32543c1
[7.2.0-preview.5] - 2021-04-14

* Breaking Changes

- Make PowerShell Linux deb and RPM packages universal (#15109)
- Enforce AppLocker Deny configuration before Execution Policy Bypass configuration (#15035)
- Disallow mixed dash and slash in command line parameter prefix (#15142) (Thanks @davidBar-On!)

* Experimental Features

- `PSNativeCommandArgumentPassing`: Use `ArgumentList` for native executable invocation (breaking change) (#14692)

* Engine Updates and Fixes

- Add `IArgumentCompleterFactory` for parameterized `ArgumentCompleters` (#12605) (Thanks @powercode!)

* General Cmdlet Updates and Fixes

- Fix SSH remoting connection never finishing with misconfigured endpoint (#15175)
- Respect `TERM` and `NO_COLOR` environment variables for `$PSStyle` rendering (#14969)
- Use `ProgressView.Classic` when Virtual Terminal is not supported (#15048)
- Fix `Get-Counter` issue with `-Computer` parameter (#15166) (Thanks @krishnayalavarthi!)
- Fix redundant iteration while splitting lines (#14851) (Thanks @hez2010!)
- Enhance `Remove-Item -Recurse` to work with OneDrive (#14902) (Thanks @iSazonov!)
- Change minimum depth to 0 for `ConvertTo-Json` (#14830) (Thanks @kvprasoon!)
- Allow `Set-Clipboard` to accept empty string (#14579)
- Turn on and off `DECCKM` to modify keyboard mode for Unix native commands to work correctly (#14943)
- Fall back to `CopyAndDelete()` when `MoveTo()` fails due to an `IOException` (#15077)

* Code Cleanup

<details>

<summary>

<p>We thank the following contributors!</p>
<p>@xtqqczze, @iSazonov, @ZhiZe-ZG</p>

</summary>

<ul>
<li>Update .NET to <code>6.0.0-preview.3</code> (#15221)</li>
<li>Add space before comma to hosting test to fix error reported by <code>SA1001</code> (#15224)</li>
<li>Add <code>SecureStringHelper.FromPlainTextString</code> helper method for efficient secure string creation (#14124) (Thanks @xtqqczze!)</li>
<li>Use static lambda keyword (#15154) (Thanks @iSazonov!)</li>
<li>Remove unnecessary <code>Array</code> -&gt; <code>List</code> -&gt; <code>Array</code> conversion in <code>ProcessBaseCommand.AllProcesses</code> (#15052) (Thanks @xtqqczze!)</li>
<li>Standardize grammar comments in Parser.cs (#15114) (Thanks @ZhiZe-ZG!)</li>
<li>Enable <code>SA1001</code>: Commas should be spaced correctly (#14171) (Thanks @xtqqczze!)</li>
<li>Refactor <code>MultipleServiceCommandBase.AllServices</code> (#15053) (Thanks @xtqqczze!)</li>
</ul>

</details>

* Tools

- Use Unix line endings for shell scripts (#15180) (Thanks @xtqqczze!)

* Tests

- Add the missing tag in Host Utilities tests (#14983)
- Update `copy-props` version in `package.json` (#15124)

* Build and Packaging Improvements

<details>

<summary>

<p>We thank the following contributors!</p>
<p>@JustinGrote</p>

</summary>

<ul>
<li>Fix <code>yarn-lock</code> for <code>copy-props</code> (#15225)</li>
<li>Make package validation regex accept universal Linux packages (#15226)</li>
<li>Bump NJsonSchema from 10.4.0 to 10.4.1 (#15190)</li>
<li>Make MSI and EXE signing always copy to fix daily build (#15191)</li>
<li>Sign internals of EXE package so that it works correctly when signed (#15132)</li>
<li>Bump Microsoft.NET.Test.Sdk from 16.9.1 to 16.9.4 (#15141)</li>
<li>Update daily release tag format to  work with new Microsoft Update work (#15164)</li>
<li>Feature: Add Ubuntu 20.04 Support to install-powershell.sh (#15095) (Thanks @JustinGrote!)</li>
<li>Treat rebuild branches like release branches (#15099)</li>
<li>Update WiX to 3.11.2 (#15097)</li>
<li>Bump NJsonSchema from 10.3.11 to 10.4.0 (#15092)</li>
<li>Allow patching of preview releases (#15074)</li>
<li>Bump Newtonsoft.Json from 12.0.3 to 13.0.1 (#15084, #15085)</li>
<li>Update the <code>minSize</code> build package filter to be explicit (#15055)</li>
<li>Bump NJsonSchema from 10.3.10 to 10.3.11 (#14965)</li>
</ul>

</details>

* Documentation and Help Content

- Merge `7.2.0-preview.4` changes to master (#15056)
- Update `README` and `metadata.json` (#15046)
- Fix broken links for `dotnet` CLI (#14937)

[7.2.0-preview.5]: v7.2.0-preview.4...v7.2.0-preview.5
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@PaulHigin
Fix SSH remoting connection hang with misconfigured endpoint (PowerSh…
258c0b7
…ell#15175)
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@TravisEz13
Merge tag 'v7.2.0-preview.5'
1d3b900
[7.2.0-preview.5] - 2021-04-14

* Breaking Changes

- Make PowerShell Linux deb and RPM packages universal (PowerShell#15109)
- Enforce AppLocker Deny configuration before Execution Policy Bypass configuration (PowerShell#15035)
- Disallow mixed dash and slash in command line parameter prefix (PowerShell#15142) (Thanks @davidBar-On!)

* Experimental Features

- `PSNativeCommandArgumentPassing`: Use `ArgumentList` for native executable invocation (breaking change) (PowerShell#14692)

* Engine Updates and Fixes

- Add `IArgumentCompleterFactory` for parameterized `ArgumentCompleters` (PowerShell#12605) (Thanks @powercode!)

* General Cmdlet Updates and Fixes

- Fix SSH remoting connection never finishing with misconfigured endpoint (PowerShell#15175)
- Respect `TERM` and `NO_COLOR` environment variables for `$PSStyle` rendering (PowerShell#14969)
- Use `ProgressView.Classic` when Virtual Terminal is not supported (PowerShell#15048)
- Fix `Get-Counter` issue with `-Computer` parameter (PowerShell#15166) (Thanks @krishnayalavarthi!)
- Fix redundant iteration while splitting lines (PowerShell#14851) (Thanks @hez2010!)
- Enhance `Remove-Item -Recurse` to work with OneDrive (PowerShell#14902) (Thanks @iSazonov!)
- Change minimum depth to 0 for `ConvertTo-Json` (PowerShell#14830) (Thanks @kvprasoon!)
- Allow `Set-Clipboard` to accept empty string (PowerShell#14579)
- Turn on and off `DECCKM` to modify keyboard mode for Unix native commands to work correctly (PowerShell#14943)
- Fall back to `CopyAndDelete()` when `MoveTo()` fails due to an `IOException` (PowerShell#15077)

* Code Cleanup

<details>

<summary>

<p>We thank the following contributors!</p>
<p>@xtqqczze, @iSazonov, @ZhiZe-ZG</p>

</summary>

<ul>
<li>Update .NET to <code>6.0.0-preview.3</code> (PowerShell#15221)</li>
<li>Add space before comma to hosting test to fix error reported by <code>SA1001</code> (PowerShell#15224)</li>
<li>Add <code>SecureStringHelper.FromPlainTextString</code> helper method for efficient secure string creation (PowerShell#14124) (Thanks @xtqqczze!)</li>
<li>Use static lambda keyword (PowerShell#15154) (Thanks @iSazonov!)</li>
<li>Remove unnecessary <code>Array</code> -&gt; <code>List</code> -&gt; <code>Array</code> conversion in <code>ProcessBaseCommand.AllProcesses</code> (PowerShell#15052) (Thanks @xtqqczze!)</li>
<li>Standardize grammar comments in Parser.cs (PowerShell#15114) (Thanks @ZhiZe-ZG!)</li>
<li>Enable <code>SA1001</code>: Commas should be spaced correctly (PowerShell#14171) (Thanks @xtqqczze!)</li>
<li>Refactor <code>MultipleServiceCommandBase.AllServices</code> (PowerShell#15053) (Thanks @xtqqczze!)</li>
</ul>

</details>

* Tools

- Use Unix line endings for shell scripts (PowerShell#15180) (Thanks @xtqqczze!)

* Tests

- Add the missing tag in Host Utilities tests (PowerShell#14983)
- Update `copy-props` version in `package.json` (PowerShell#15124)

* Build and Packaging Improvements

<details>

<summary>

<p>We thank the following contributors!</p>
<p>@JustinGrote</p>

</summary>

<ul>
<li>Fix <code>yarn-lock</code> for <code>copy-props</code> (PowerShell#15225)</li>
<li>Make package validation regex accept universal Linux packages (PowerShell#15226)</li>
<li>Bump NJsonSchema from 10.4.0 to 10.4.1 (PowerShell#15190)</li>
<li>Make MSI and EXE signing always copy to fix daily build (PowerShell#15191)</li>
<li>Sign internals of EXE package so that it works correctly when signed (PowerShell#15132)</li>
<li>Bump Microsoft.NET.Test.Sdk from 16.9.1 to 16.9.4 (PowerShell#15141)</li>
<li>Update daily release tag format to  work with new Microsoft Update work (PowerShell#15164)</li>
<li>Feature: Add Ubuntu 20.04 Support to install-powershell.sh (PowerShell#15095) (Thanks @JustinGrote!)</li>
<li>Treat rebuild branches like release branches (PowerShell#15099)</li>
<li>Update WiX to 3.11.2 (PowerShell#15097)</li>
<li>Bump NJsonSchema from 10.3.11 to 10.4.0 (PowerShell#15092)</li>
<li>Allow patching of preview releases (PowerShell#15074)</li>
<li>Bump Newtonsoft.Json from 12.0.3 to 13.0.1 (PowerShell#15084, PowerShell#15085)</li>
<li>Update the <code>minSize</code> build package filter to be explicit (PowerShell#15055)</li>
<li>Bump NJsonSchema from 10.3.10 to 10.3.11 (PowerShell#14965)</li>
</ul>

</details>

* Documentation and Help Content

- Merge `7.2.0-preview.4` changes to master (PowerShell#15056)
- Update `README` and `metadata.json` (PowerShell#15046)
- Fix broken links for `dotnet` CLI (PowerShell#14937)

[7.2.0-preview.5]: PowerShell/PowerShell@v7.2.0-preview.4...v7.2.0-preview.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov approved these changes
@anamnavi Anam Navied (anamnavi) Awaiting requested review from anamnavi
+1 more reviewer
@JamesWTruher James Truher (JamesWTruher) JamesWTruher approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Remoting PSRP issues with any transport layer

Projects

None yet

Milestone

7.2.0-preview.5

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@PaulHigin @TravisEz13 @JamesWTruher @iSazonov @daxian-dbw
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 01402520 — 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.