[Regression] Fix for error on Enter-PSSession exit#4693
[Regression] Fix for error on Enter-PSSession exit#4693mirichmo merged 3 commits intoPowerShell:masterfrom PaulHigin:fix-ssh-erroronexit
Conversation
| private StreamWriter _stdInWriter; | ||
| private StreamReader _stdOutReader; | ||
| private StreamReader _stdErrReader; | ||
| private bool _connectionEstablished; |
There was a problem hiding this comment.
should this have an explicit initialization to false?
There was a problem hiding this comment.
No need as CLR guarantees all type fields are initialized to zero.
| else | ||
| { | ||
| // Normal output data. | ||
| if (!_connectionEstablished) { _connectionEstablished = true; } |
There was a problem hiding this comment.
should this just be simply _connectionEstablished = true
There was a problem hiding this comment.
I prefer to do the assignment only once in the loop.
| private StreamWriter _stdInWriter; | ||
| private StreamReader _stdOutReader; | ||
| private StreamReader _stdErrReader; | ||
| private bool _connectionEstablished; |
There was a problem hiding this comment.
should this be an explicit initialization to false?
There was a problem hiding this comment.
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.
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.
This is a common pattern we use for Cmdlet async StopProcessing. I'll add a comment.
There was a problem hiding this comment.
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.
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.
SteveL-MSFT
left a comment
There was a problem hiding this comment.
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.
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.
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.