Skip to content

Commit

Permalink
fix: exec hang
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Apr 17, 2023
1 parent 8682335 commit 4204df9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/KubernetesClient/KubernetesClientConfiguration.ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace k8s
Expand Down Expand Up @@ -557,7 +558,30 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co
throw new KubeConfigException($"external exec failed due to: {ex.Message}");
}

var stderr = process.StandardError.ReadLine();
var sb = new StringBuilder();
var buffer = new char[1];
while (true)
{
var readTask = process.StandardError.ReadAsync(buffer, 0, buffer.Length);

if (readTask.Wait(TimeSpan.FromSeconds(2)))
{
var bytesRead = readTask.Result;
if (bytesRead == 0)
{
break; // end of stream reached
}

sb.Append(buffer, 0, bytesRead);
}
else
{
// timeout occurred
break;
}
}

var stderr = sb.ToString();

if (!string.IsNullOrWhiteSpace(stderr))
{
Expand Down

0 comments on commit 4204df9

Please sign in to comment.