Skip to content
9 changes: 8 additions & 1 deletion src/KubernetesClient/StreamDemuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected async Task RunLoop(CancellationToken cancellationToken)
{
// Get a 1KB buffer
byte[] buffer = ArrayPool<byte>.Shared.Rent(1024 * 1024);

int byteCount = 0;
try
{
var segment = new ArraySegment<byte>(buffer);
Expand All @@ -199,6 +199,13 @@ protected async Task RunLoop(CancellationToken cancellationToken)

var streamIndex = buffer[0];
var extraByteCount = 1;
byteCount += result.Count - extraByteCount;
if (byteCount <= 2)
{
// The first 2 bytes from the web socket is port bytes, skip.
// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/server/portforward/websocket.go
continue;
}

while (true)
{
Expand Down