Skip to content

Commit d9bca19

Browse files
brendandburnsk8s-ci-robot
authored andcommitted
Fix port-forward example (#309)
1 parent 239125a commit d9bca19

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/portforward/PortForward.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private static async Task Main(string[] args)
2424
private async static Task Forward(IKubernetes client, V1Pod pod) {
2525
// Note this is single-threaded, it won't handle concurrent requests well...
2626
var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] {80}, "v4.channel.k8s.io");
27-
var demux = new StreamDemuxer(webSocket);
27+
var demux = new StreamDemuxer(webSocket, StreamType.PortForward);
2828
demux.Start();
2929

3030
var stream = demux.GetStream((byte?)0, (byte?)0);
@@ -37,6 +37,7 @@ private async static Task Forward(IKubernetes client, V1Pod pod) {
3737

3838
Socket handler = null;
3939

40+
// Note this will only accept a single connection
4041
var accept = Task.Run(() => {
4142
while (true) {
4243
handler = listener.Accept();
@@ -61,6 +62,10 @@ private async static Task Forward(IKubernetes client, V1Pod pod) {
6162

6263
await accept;
6364
await copy;
65+
if (handler != null) {
66+
handler.Close();
67+
}
68+
listener.Close();
6469
}
6570
}
6671
}

0 commit comments

Comments
 (0)