From a3ed83b9313a2be7def7dac84d38d655be04b3a8 Mon Sep 17 00:00:00 2001 From: Anirudh Date: Wed, 8 Feb 2017 12:36:22 -0800 Subject: [PATCH 1/2] Fix high latency when websocket connection fails --- .../client/dsl/internal/WatchConnectionManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java index 2847f4d7688..2cf61db3840 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java @@ -55,6 +55,7 @@ import static io.fabric8.kubernetes.client.utils.Utils.isNotNullOrEmpty; import static java.net.HttpURLConnection.HTTP_GONE; +import static java.net.HttpURLConnection.HTTP_OK; public class WatchConnectionManager> implements Watch { @@ -193,6 +194,13 @@ public void onFailure(IOException e, Response response) { return; } + if (response != null && response.code() == HTTP_OK) { + queue.add(new KubernetesClientException("Received 200 on WebSocket connection", + response.code(), null)); + response.body().close(); + return; + } + if (response != null) { // We only need to queue startup failures. Status status = OperationSupport.createStatus(response); From fc394c90d1b8c0046d68e6c55457128d0bca969a Mon Sep 17 00:00:00 2001 From: Anirudh Date: Wed, 8 Feb 2017 12:43:42 -0800 Subject: [PATCH 2/2] Added comment --- .../client/dsl/internal/WatchConnectionManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java index 2cf61db3840..986d1ce0396 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/WatchConnectionManager.java @@ -194,8 +194,10 @@ public void onFailure(IOException e, Response response) { return; } + // We do not expect a 200 in response to the websocket connection. If it occurs, we throw + // an exception and try the watch via a persistent HTTP Get. if (response != null && response.code() == HTTP_OK) { - queue.add(new KubernetesClientException("Received 200 on WebSocket connection", + queue.add(new KubernetesClientException("Received 200 on websocket", response.code(), null)); response.body().close(); return;