From 231e108e91f70f19863bc8377ab3bfda71991091 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Wed, 22 Mar 2023 15:00:55 -0400 Subject: [PATCH] fix #4988: ensuring the previous --- CHANGELOG.md | 1 + .../client/http/StandardHttpClient.java | 1 + .../client/http/StandardHttpClientTest.java | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50633c64cd4..82dfc4b9cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ #### Bugs * Fix #4963: Openshift Client return 403 when use websocket +* Fix #4988: Ensuring that previous requests are closed before retry #### Improvements * Fix #4477 exposing LeaderElector.release to force an elector to give up the lease 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 e399cbd5251..06bc0da0785 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 @@ -142,6 +142,7 @@ protected void retryWithExponentialBackoff(CompletableFuture result, LOG.debug("HTTP operation on url: {} should be retried as the response code was {}, retrying after {} millis", uri, code, retryInterval); retry = true; + cancel.accept(response); } } else if (throwable instanceof IOException) { LOG.debug(String.format("HTTP operation on url: %s should be retried after %d millis because of IOException", diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/StandardHttpClientTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/StandardHttpClientTest.java index 5e308c28bac..c74ecf188ed 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/StandardHttpClientTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/http/StandardHttpClientTest.java @@ -184,4 +184,30 @@ void testWebSocketWithLessFailuresThanRetries() throws Exception { assertEquals(3, client.getWsFutures().size()); } + @Test + void testClosePreviousBeforeRetry() throws Exception { + client = client.newBuilder().tag(new RequestConfigBuilder() + .withRequestRetryBackoffLimit(1) + .withRequestRetryBackoffInterval(50).build()) + .build(); + + final HttpResponse error = new TestHttpResponse().withBody(Mockito.mock(AsyncBody.class)) + .withCode(503); + client.getRespFutures().add(CompletableFuture.completedFuture(error)); + client.getRespFutures().add(CompletableFuture.completedFuture(new TestHttpResponse().withCode(200))); + + CompletableFuture> consumeFuture = client.consumeBytes( + client.newHttpRequestBuilder().uri("http://localhost").build(), + (value, asyncBody) -> { + }); + + Mockito.verify(error.body()).cancel(); + + // should ultimately succeed with the final 200 + assertEquals(200, consumeFuture.get().code()); + + // only 2 requests issued + assertEquals(2, client.getRespFutures().size()); + } + }