Skip to content

Commit

Permalink
Redundantly cancel timeout future
Browse files Browse the repository at this point in the history
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 <robeyoun@redhat.com>
  • Loading branch information
robobario committed Feb 6, 2024
1 parent d5193d8 commit 8560e22
Showing 1 changed file with 2 additions and 4 deletions.
Expand Up @@ -305,11 +305,9 @@ private <F extends FilterResult> CompletableFuture<F> 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) {
Expand Down

0 comments on commit 8560e22

Please sign in to comment.