Skip to content

Commit

Permalink
Move afterConnectionFailure callback to retryWithExponentialBackoff
Browse files Browse the repository at this point in the history
… so its invoked when an established websocket connection fails
  • Loading branch information
SamBarker committed Jul 22, 2024
1 parent 39e6e12 commit 0b17eda
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ private CompletableFuture<HttpResponse<AsyncBody>> consumeBytesOnce(StandardHttp
final Consumer<List<ByteBuffer>> effectiveConsumer = consumer;

CompletableFuture<HttpResponse<AsyncBody>> 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)));

Expand Down Expand Up @@ -184,15 +177,19 @@ private <V> CompletableFuture<V> 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;
}
}
Expand Down

0 comments on commit 0b17eda

Please sign in to comment.