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 for Linux platform PowerShell exit on error during SSH remoting connection by PaulHigin · Pull Request #4993 · PowerShell/PowerShell

Conversation

@PaulHigin

@PaulHigin Paul Higinbotham (PaulHigin) commented Oct 3, 2017

Copy link
Copy Markdown
Contributor

This fixes addresses issue #4940.

The problem is that the connection clean up code in SSHClientSessionTransportManager would try to terminate a process with id == 0, which is the initial value for the _sshProcessId field when no SSH process has been created yet. For both Linux and Windows platforms process id of zero is a special process and should not be terminated. Fortunately those processes are not terminated by the existing code but on Linux platforms the PowerShell parent process exits immediately.

The fix is to add checks that the SSH process has been created and is valid before terminating it during connection cleanup.

Sorry, something went wrong.

Uh oh!

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

All reactions
@PaulHigin
Fix for Linux platform PowerShell exit on error during SSH remoting c…
2695e00
…onnection
@PaulHigin Paul Higinbotham (PaulHigin) added WG-Remoting PSRP issues with any transport layer Issue-Bug Issue has been identified as a bug in the product OS-Linux OS-macOS labels Oct 3, 2017
@PaulHigin Paul Higinbotham (PaulHigin) added this to the 6.0.0-HighPriority milestone Oct 3, 2017
@PaulHigin Paul Higinbotham (PaulHigin) assigned Mike Richmond (mirichmo) Oct 3, 2017
@PaulHigin
Paul Higinbotham (PaulHigin) requested a review from Steve Lee (SteveL-MSFT) October 3, 2017 18:21
@PaulHigin
Paul Higinbotham (PaulHigin) requested review from Dan Travison (dantraMSFT) and Mike Richmond (mirichmo) as code owners October 3, 2017 18:21
dantraMSFT
Dan Travison (dantraMSFT) approved these changes Oct 3, 2017
View reviewed changes

@dantraMSFT Dan Travison (dantraMSFT) left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
SteveL-MSFT
Steve Lee (SteveL-MSFT) requested changes Oct 3, 2017
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs
if (stdErrReader != null) { stdErrReader.Dispose(); }

try
var sshProcessId = _sshProcessId;

@SteveL-MSFT Steve Lee (SteveL-MSFT) Oct 3, 2017

Copy link
Copy Markdown
Member

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.

Can't you use _sshProcessId directly instead of creating a new variable?

Sorry, something went wrong.

Uh oh!

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

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Oct 3, 2017

Copy link
Copy Markdown
Contributor Author

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.

CloseConnection can be called from multiple places (state machine, error handling) and this is just to prevent going through this code path multiple times. I am not concerned about race conditions since Process type is thread safe ... I just want to prevent running the code path after the process has been terminated.

I'll add a comment to clarify.

Sorry, something went wrong.

Uh oh!

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

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

try
var sshProcessId = _sshProcessId;
_sshProcessId = 0;

@SteveL-MSFT Steve Lee (SteveL-MSFT) Oct 3, 2017

Copy link
Copy Markdown
Member

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.

Perhaps initialize it to 0 in the constructor instead of resetting it here?

Sorry, something went wrong.

Uh oh!

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

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Oct 3, 2017

Copy link
Copy Markdown
Contributor Author

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.

CLR guarantees all fields are initialized to zero. I am setting it back to zero here to prevent the code path running twice (see comment above).

Sorry, something went wrong.

Uh oh!

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

All reactions
@PaulHigin
Added comment for clarification per code review request
6ff7c85
SteveL-MSFT
Steve Lee (SteveL-MSFT) approved these changes Oct 3, 2017
View reviewed changes
mirichmo
Mike Richmond (mirichmo) approved these changes Oct 4, 2017
View reviewed changes
@mirichmo
Mike Richmond (mirichmo) merged commit 5b54e4d into PowerShell:master Oct 4, 2017
@PaulHigin
Paul Higinbotham (PaulHigin) deleted the Fix-SSHRemoting-PowerShell-Exit branch October 4, 2017 15:15
@PaulHigin Paul Higinbotham (PaulHigin) mentioned this pull request Oct 4, 2017
PowerShell exits opening runspace created with SSHConnectionInfo #4940
Closed
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@PaulHigin @mirichmo
Fix for Linux platform PowerShell exit on error during SSH remoting c…
07e45ca
…onnection (PowerShell#4993)

* Fix for Linux platform PowerShell exit on error during SSH remoting connection

* Added comment for clarification per code review request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@SteveL-MSFT Steve Lee (SteveL-MSFT) SteveL-MSFT approved these changes
+2 more reviewers
@dantraMSFT Dan Travison (dantraMSFT) dantraMSFT approved these changes
@mirichmo Mike Richmond (mirichmo) mirichmo approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@mirichmo Mike Richmond (mirichmo)

Labels

Issue-Bug Issue has been identified as a bug in the product OS-Linux OS-macOS WG-Remoting PSRP issues with any transport layer

Projects

None yet

Milestone

6.0.0-GA

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@PaulHigin @SteveL-MSFT @dantraMSFT @mirichmo
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 01402503 — 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.