Skip to content

Commit 748d97a

Browse files
committed
fix fabric8io#4365 correcting backoff interval
also adding stacktraces for blocking request exceptions
1 parent 3eb233f commit 748d97a

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/OperationSupport.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class OperationSupport {
8383
protected String apiGroupVersion;
8484
protected boolean dryRun;
8585
private final int requestRetryBackoffLimit;
86+
private final int requestRetryBackoffInterval;
8687

8788
public OperationSupport(Client client) {
8889
this(new OperationContext().withClient(client));
@@ -106,8 +107,10 @@ public OperationSupport(OperationContext ctx) {
106107
}
107108

108109
if (ctx.getConfig() != null) {
110+
requestRetryBackoffInterval = ctx.getConfig().getRequestRetryBackoffInterval();
109111
this.requestRetryBackoffLimit = ctx.getConfig().getRequestRetryBackoffLimit();
110112
} else {
113+
requestRetryBackoffInterval = Config.DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
111114
this.requestRetryBackoffLimit = Config.DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
112115
}
113116
}
@@ -508,15 +511,11 @@ protected <T> T waitForResult(CompletableFuture<T> future) throws IOException {
508511
if (e.getCause() != null) {
509512
t = e.getCause();
510513
}
514+
// throw a new exception to preserve the calling stack trace
511515
if (t instanceof IOException) {
512-
throw (IOException) t;
516+
throw new IOException(t.getMessage(), t);
513517
}
514-
if (t instanceof RuntimeException) {
515-
throw (RuntimeException) t;
516-
}
517-
InterruptedIOException ie = new InterruptedIOException();
518-
ie.initCause(e);
519-
throw ie;
518+
throw new KubernetesClientException(t.getMessage(), t);
520519
}
521520
}
522521

@@ -568,7 +567,7 @@ protected <T> CompletableFuture<T> handleResponse(HttpClient client, HttpRequest
568567
HttpRequest request = requestBuilder.build();
569568
CompletableFuture<HttpResponse<byte[]>> futureResponse = new CompletableFuture<>();
570569
retryWithExponentialBackoff(futureResponse,
571-
new ExponentialBackoffIntervalCalculator(requestRetryBackoffLimit, MAX_RETRY_INTERVAL_EXPONENT),
570+
new ExponentialBackoffIntervalCalculator(requestRetryBackoffInterval, MAX_RETRY_INTERVAL_EXPONENT),
572571
Utils.getNonNullOrElse(client, httpClient), request);
573572

574573
return futureResponse.thenApply(response -> {

kubernetes-client/src/test/java/io/fabric8/kubernetes/client/dsl/internal/BaseOperationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ void testNoHttpRetryWithDefaultConfig() {
296296
void testHttpRetryWithMoreFailuresThanRetries() {
297297
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
298298
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 1000);
299+
long start = System.currentTimeMillis();
299300
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext()
300301
.withClient(mockClient(mockClient,
301302
new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").withNamespace("default")
@@ -309,7 +310,10 @@ void testHttpRetryWithMoreFailuresThanRetries() {
309310
Pod result = baseOp.get();
310311
});
311312

313+
long stop = System.currentTimeMillis();
314+
312315
// Then
316+
assertTrue(stop - start >= 700); //100+200+400
313317
assertTrue(exception.getMessage().contains("Internal Server Error"),
314318
"As the last failure, the 3rd one, is not an IOException the message expected to contain: 'Internal Server Error'!");
315319
assertEquals(4, httpExecutionCounter.get(), "Expected 4 calls: one normal try and 3 backoff retries!");

0 commit comments

Comments
 (0)