From 4ed76d1ebbaa40357d06cdf1f85d807d5b79ebeb Mon Sep 17 00:00:00 2001 From: Robert Young Date: Mon, 5 Feb 2024 14:10:27 +1300 Subject: [PATCH] Redundantly cancel timeout future Why: If the filter completed it's future exceptionally, then the thenApplyAsync block that cancelled the timeout future was never called. By using a whenComplete we will cancel the timeout on the success and failure path. It's also safe to redundantly cancel it if the failure was being triggered by the timeout future itself. Signed-off-by: Robert Young --- .../java/io/kroxylicious/proxy/internal/FilterHandler.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/internal/FilterHandler.java b/kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/internal/FilterHandler.java index e33a727af8..aaf0595d91 100644 --- a/kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/internal/FilterHandler.java +++ b/kroxylicious-runtime/src/main/java/io/kroxylicious/proxy/internal/FilterHandler.java @@ -301,11 +301,9 @@ private CompletableFuture handleDeferredStage(Decode } future.completeExceptionally(new TimeoutException("Filter %s was timed-out.".formatted(filterDescriptor()))); }, timeoutMs, TimeUnit.MILLISECONDS); - return future.thenApplyAsync(filterResult -> { + return future.whenComplete((f, throwable) -> { timeoutFuture.cancel(false); - - return filterResult; - }, ctx.executor()); + }).thenApplyAsync(filterResult -> filterResult, ctx.executor()); } private void deferredResponseCompleted(ResponseFilterResult ignored, Throwable throwable) {