Fix for SSH remoting when SSH client abruptly terminates (#4123)

* Fix for SSH remoting when SSH client abruptly terminates

* Put error message in localizable string resource

* Renamed error string per code review request

* Removed extra error==null check
This commit is contained in:
Paul Higinbotham 2017-06-29 11:14:33 -07:00 committed by Mike Richmond
parent a8e3d8968f
commit a2922d6ac4
2 changed files with 17 additions and 2 deletions

View file

@ -1511,8 +1511,10 @@ namespace System.Management.Automation.Remoting.Client
while (true)
{
string error = ReadError(reader);
if (string.IsNullOrEmpty(error))
if (error.Length == 0)
{
// Ignore
continue;
}
@ -1524,6 +1526,10 @@ namespace System.Management.Automation.Remoting.Client
HandleSSHError(psrte);
}
}
catch (ObjectDisposedException)
{
// Normal reader thread end.
}
catch (Exception e)
{
string errorMsg = (e.Message != null) ? e.Message : string.Empty;
@ -1548,7 +1554,13 @@ namespace System.Management.Automation.Remoting.Client
// Blocking read from StdError stream
string error = reader.ReadLine();
if (string.IsNullOrEmpty(error) ||
if (error == null)
{
// Stream is closed unexpectedly.
throw new PSInvalidOperationException(RemotingErrorIdStrings.SSHAbruptlyTerminated);
}
if ((error.Length == 0) ||
error.IndexOf("WARNING:", StringComparison.OrdinalIgnoreCase) > -1)
{
// Handle as interactive warning message

View file

@ -1636,4 +1636,7 @@ All WinRM sessions connected to Windows PowerShell session configurations, such
<data name="InvalidRoleCapabilityFileExtension" xml:space="preserve">
<value>The provided role capability file {0} does not have the required .psrc extension.</value>
</data>
<data name="SSHAbruptlyTerminated" >
<value>The SSH transport process has abruptly terminated causing this remote session to break.</value>
</data>
</root>