From 0b17edac26f00627df1ff9ee56d0e5b8b61cc7be Mon Sep 17 00:00:00 2001 From: Sam Barker Date: Tue, 23 Jul 2024 09:22:29 +1200 Subject: [PATCH] Move afterConnectionFailure callback to `retryWithExponentialBackoff` so its invoked when an established websocket connection fails --- .../client/http/StandardHttpClient.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/StandardHttpClient.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/StandardHttpClient.java index 4e54081732f..1c350f063af 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/StandardHttpClient.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/http/StandardHttpClient.java @@ -108,13 +108,6 @@ private CompletableFuture> consumeBytesOnce(StandardHttp final Consumer> effectiveConsumer = consumer; CompletableFuture> cf = consumeBytesDirect(effectiveRequest, effectiveConsumer); - cf.exceptionally(throwable -> { - builder.interceptors.forEach((s, interceptor) -> interceptor.afterConnectionFailure(effectiveRequest, throwable)); - if (throwable instanceof CompletionException) { - throw (CompletionException) throwable; - } - throw new CompletionException(throwable); - }); cf.thenAccept( response -> builder.getInterceptors().values().forEach(i -> i.after(effectiveRequest, response, effectiveConsumer))); @@ -184,15 +177,19 @@ private CompletableFuture retryWithExponentialBackoff( } } } else { + final Throwable finalThrowable; if (throwable instanceof CompletionException) { - throwable = throwable.getCause(); + finalThrowable = throwable.getCause(); + } else { + finalThrowable = throwable; } - if (throwable instanceof IOException) { + builder.interceptors.forEach((s, interceptor) -> interceptor.afterConnectionFailure(request, finalThrowable)); + if (finalThrowable instanceof IOException) { // TODO: may not be specific enough - incorrect ssl settings for example will get caught here LOG.debug( String.format("HTTP operation on url: %s should be retried after %d millis because of IOException", uri, retryInterval), - throwable); + finalThrowable); return true; } }