8000 Fix for Linux platform PowerShell exit on error during SSH remoting connection by PaulHigin · Pull Request #4993 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2017
Merged

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

merged 2 commits into from
Oct 4, 2017

Conversation

PaulHigin
Copy link
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.

@PaulHigin 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 PaulHigin added this to the 6.0.0-HighPriority milestone Oct 3, 2017
@PaulHigin PaulHigin requested a review from SteveL-MSFT October 3, 2017 18:21
Copy link
Contributor
@dantraMSFT dantraMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1488,18 +1488,23 @@ private void CloseConnection()
var stdErrReader = _stdErrReader;
if (stdErrReader != null) { stdErrReader.Dispose(); }

try
var sshProcessId = _sshProcessId;
Copy link
Member

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?

Copy link
Contributor Author

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.

@@ -1488,18 +1488,23 @@ private void CloseConnection()
var stdErrReader = _stdErrReader;
if (stdErrReader != null) { stdErrReader.Dispose(); }

try
var sshProcessId = _sshProcessId;
_sshProcessId = 0;
Copy link
Member

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?

Copy link
Contributor Author

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).

@mirichmo mirichmo merged commit 5b54e4d into PowerShell:master Oct 4, 2017
@PaulHigin PaulHigin deleted the Fix-SSHRemoting-PowerShell-Exit branch October 4, 2017 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Development

Successfully merging this pull request may close these issues.

4 participants
0