-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Regression] Fix for error on Enter-PSSession exit #4693
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
Conversation
@@ -1403,6 +1403,7 @@ internal sealed class SSHClientSessionTransportManager : OutOfProcessClientSessi | |||
private StreamWriter _stdInWriter; | |||
private StreamReader _stdOutReader; | |||
private StreamReader _stdErrReader; | |||
private bool _connectionEstablished; |
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.
should this have an explicit initialization to false?
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.
No need as CLR guarantees all type fields are initialized to zero.
@@ -1642,6 +1648,7 @@ private void ProcessReaderThread(object state) | |||
else | |||
{ | |||
// Normal output data. | |||
if (!_connectionEstablished) { _connectionEstablished = true; } |
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.
should this just be simply _connectionEstablished = true
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.
I prefer to do the assignment only once in the loop.
@@ -1403,6 +1403,7 @@ internal sealed class SSHClientSessionTransportManager : OutOfProcessClientSessi | |||
private StreamWriter _stdInWriter; | |||
private StreamReader _stdOutReader; | |||
private StreamReader _stdErrReader; | |||
private bool _connectionEstablished; |
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.
should this be an explicit initialization to false?
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.
No need as CLR guarantees all type fields are initialized to zero.
Thanks! |
You continue processing data so why isn't this also considered a _connectionEstablished state? As it stands, it appears that there is a nebulas state where errors are processed but the connection cannot be closed via CloseAsync. Refers to: src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs:1645 in 5924f77. [](commit_id = 5924f77, deletion_comment = False) |
remoteRunspace.Open(); | ||
remoteRunspace.ShouldCloseOnPop = true; | ||
|
||
_tempRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace; |
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.
You should comment why _tempRunspace is being used. On the surface, the usage either implies reentrancy or threading issue; if so, StopProcessing's use of _tempRunspace is problematic. Comments explaining it's expected usage would help.
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.
This is a common pattern we use for Cmdlet async StopProcessing. I'll add a comment.
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.
Regarding above comment about connection established. I think it is possible for an error to occur before the first PSRP message is processed.
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.
However, we want to do immediate connection clean up only if PSRP messages are being processed because then we can rely on the protocol to clean up the client connection state. This is just for the case where the session is abruptly severed and we can't count on PSRP for clean up. I'll add comment to clarify.
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.
The second source file isn't showing a diff and usually this is caused by one of them having LF and the other CRLF endings. Usually what I do is explicitly save it with LF endings and push it and the diff will show up correctly.
Thanks! Will fix. |
@mirichmo |
@dantraMSFT |
// is established. | ||
_tempRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace; | ||
_tempRunspace.Open(); | ||
_tempRunspace.ShouldCloseOnPop = true; |
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.
Isn't this an order of operations issue? It seems like the flag should be set before the call to Open().
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.
Do you mean the ShouldCloseOnPop property? No. A runspace pop cannot occur before this method completes.
This is a fix for issue #4686.
I inadvertently created this regression with PR #4475. The problem is that connection state is terminated before the session close sequence completes. The fix is to only clean up connection state on session close if the session was never established.
I also added code to Enter-PSSession to handle a similar case where the Cmdlet operation is stopped before the connection or session is created. This is important for SSH remoting because PowerShell interacts with SSH and it is possible to cancel before a connection is even started.