Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion experimental-feature-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"PSCommandNotFoundSuggestion",
"PSLoadAssemblyFromNativeCode",
"PSNativeCommandErrorActionPreference",
"PSRemotingSSHTransportErrorHandling",
"PSSubsystemPluginModel"
]
1 change: 0 additions & 1 deletion experimental-feature-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"PSCommandNotFoundSuggestion",
"PSLoadAssemblyFromNativeCode",
"PSNativeCommandErrorActionPreference",
"PSRemotingSSHTransportErrorHandling",
"PSSubsystemPluginModel"
]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ExperimentalFeature

internal const string EngineSource = "PSEngine";
internal const string PSNativeCommandErrorActionPreferenceFeatureName = "PSNativeCommandErrorActionPreference";
internal const string PSRemotingSSHTransportErrorHandling = "PSRemotingSSHTransportErrorHandling";

#endregion

Expand Down Expand Up @@ -116,10 +115,7 @@ static ExperimentalFeature()
description: "Expose an API to allow assembly loading from native code"),
new ExperimentalFeature(
name: PSNativeCommandErrorActionPreferenceFeatureName,
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true"),
new ExperimentalFeature(
name: PSRemotingSSHTransportErrorHandling,
description: "Removes the SSH remoting transport stdErr stream message handling as terminating errors, and instead just writes error messages to console.")
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true")
};

EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,50 +1819,30 @@ private void ProcessErrorThread(object state)
{
string error;

if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSRemotingSSHTransportErrorHandling))
{
// Blocking read from StdError stream
error = reader.ReadLine();

if (error == null)
{
// Stream is closed unexpectedly.
throw new PSInvalidOperationException(RemotingErrorIdStrings.SSHAbruptlyTerminated);
}

if (error.Length == 0)
{
// Ignore
continue;
}

try
{
// Messages in error stream from ssh are unreliable, and may just be warnings or
// banner text.
// So just report the messages but don't act on them.
System.Console.WriteLine(error);
}
catch (IOException)
{ }
// Blocking read from StdError stream
error = reader.ReadLine();

continue;
if (error == null)
{
// Stream is closed unexpectedly.
throw new PSInvalidOperationException(RemotingErrorIdStrings.SSHAbruptlyTerminated);
}

error = ReadError(reader);

if (error.Length == 0)
{
// Ignore
continue;
}

// Any SSH client error results in a broken session.
PSRemotingTransportException psrte = new PSRemotingTransportException(
PSRemotingErrorId.IPCServerProcessReportedError,
RemotingErrorIdStrings.IPCServerProcessReportedError,
StringUtil.Format(RemotingErrorIdStrings.SSHClientEndWithErrorMessage, error));
HandleSSHError(psrte);
try
{
// Messages in error stream from ssh are unreliable, and may just be warnings or
// banner text.
// So just report the messages but don't act on them.
System.Console.WriteLine(error);
}
catch (IOException)
{ }
}
}
catch (ObjectDisposedException)
Expand All @@ -1888,55 +1868,6 @@ private void HandleSSHError(PSRemotingTransportException psrte)
CloseConnection();
}

private static string ReadError(StreamReader reader)
{
// Blocking read from StdError stream
string error = reader.ReadLine();

if (error == null)
{
// Stream is closed unexpectedly.
throw new PSInvalidOperationException(RemotingErrorIdStrings.SSHAbruptlyTerminated);
}

if ((error.Length == 0) ||
error.Contains("WARNING:", StringComparison.OrdinalIgnoreCase))
{
// Handle as interactive warning message
Console.WriteLine(error);
return string.Empty;
}

// SSH may return a multi-line error message.
// The StdError pipe stream is open ended causing StreamReader read operations to block
// if there is no incoming data. Since we don't know how many error message lines there
// will be we use an asynchronous read with timeout to prevent blocking indefinitely.
System.Text.StringBuilder sb = new Text.StringBuilder(error);
var running = true;
while (running)
{
try
{
var task = reader.ReadLineAsync();
if (task.Wait(1000) && (task.Result != null))
{
sb.Append(Environment.NewLine);
sb.Append(task.Result);
}
else
{
running = false;
}
}
catch (Exception)
{
running = false;
}
}

return sb.ToString();
}

private void StartReaderThread(
StreamReader reader)
{
Expand Down