Skip to content

Commit

Permalink
chore: add StandardOutput timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Apr 18, 2023
1 parent 9eecb4a commit 8571591
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,23 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
throw new KubeConfigException($"external exec failed due to: {stderr}");
}

var stdout = process.StandardOutput.ReadToEnd();

// Wait for a maximum of 5 seconds, if a response takes longer probably something went wrong...
process.WaitForExit(5);
var stdOutTask = process.StandardOutput.ReadToEndAsync();

string stdOut;

if (stdOutTask.Wait(TimeSpan.FromSeconds(5)))
{
stdOut = stdOutTask.Result;
}
else
{
throw new KubeConfigException("external exec failed due to timeout");
}

try
{
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(stdout);
var responseObject = KubernetesJson.Deserialize<ExecCredentialResponse>(stdOut);
if (responseObject == null || responseObject.ApiVersion != config.ApiVersion)
{
throw new KubeConfigException(
Expand Down

0 comments on commit 8571591

Please sign in to comment.