Skip to content
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

fix: Exec hangs #1267

Merged
merged 18 commits into from
May 1, 2023
Merged
Changes from 9 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
21 changes: 15 additions & 6 deletions src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,24 +548,33 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co

var process = CreateRunnableExternalProcess(config);

var stdout = "";
var stderr = "";

process.OutputDataReceived += (sender, args) => stdout += args.Data;
process.ErrorDataReceived += (sender, args) => stderr += args.Data;

try
{
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
catch (Exception ex)
{
throw new KubeConfigException($"external exec failed due to: {ex.Message}");
}

var stdout = process.StandardOutput.ReadToEnd();
var stderr = process.StandardError.ReadToEnd();
if (string.IsNullOrWhiteSpace(stderr) == false)
// Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
if (!process.WaitForExit(5000) && string.IsNullOrWhiteSpace(stderr))
IvanJosipovic marked this conversation as resolved.
Show resolved Hide resolved
{
throw new KubeConfigException($"external exec failed due to: {stderr}");
throw new KubeConfigException("external exec failed due to timeout");
}

// Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
process.WaitForExit(5);
if (!string.IsNullOrWhiteSpace(stderr))
{
throw new KubeConfigException($"external exec failed due to: {stderr}");
}

try
{
Expand Down