-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Fix for Linux platform PowerShell exit on error during SSH remoting connection #4993
Conversation
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
@@ -1488,18 +1488,23 @@ private void CloseConnection() | |||
var stdErrReader = _stdErrReader; | |||
if (stdErrReader != null) { stdErrReader.Dispose(); } | |||
|
|||
try | |||
var sshProcessId = _sshProcessId; |
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?
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.
@@ -1488,18 +1488,23 @@ private void CloseConnection() | |||
var stdErrReader = _stdErrReader; | |||
if (stdErrReader != null) { stdErrReader.Dispose(); } | |||
|
|||
try | |||
var sshProcessId = _sshProcessId; | |||
_sshProcessId = 0; |
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?
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).
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.