diff --git a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs
index a1a8972ca..90a5be4cf 100644
--- a/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs
+++ b/src/System.Management.Automation/engine/remoting/fanin/OutOfProcTransportManager.cs
@@ -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
diff --git a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
index 9baf3b5ac..7b21c4be9 100644
--- a/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
+++ b/src/System.Management.Automation/resources/RemotingErrorIdStrings.resx
@@ -1636,4 +1636,7 @@ All WinRM sessions connected to Windows PowerShell session configurations, such
The provided role capability file {0} does not have the required .psrc extension.
+
+ The SSH transport process has abruptly terminated causing this remote session to break.
+