RFR: JDK-8303742: CompletableFuture.orTimeout leaks if the future completes exceptionally [v5]

Alan Bateman alanb at openjdk.org
Fri Mar 17 09:24:55 UTC 2023


On Fri, 17 Mar 2023 09:18:07 GMT, Viktor Klang <duke at openjdk.org> wrote:

>> Addresses the situation where exceptional completion of `orTimeout`:ed CompletableFutures wouldn't cancel the timeout task which could lead to memory leaks if done frequently enough with long enough timeout durations.
>> 
>> Fix discussed with @DougLea
>
> Viktor Klang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   while-statement formatting update

test/jdk/java/util/concurrent/CompletableFuture/CompletableFutureOrTimeoutExceptionallyTest.java line 58:

> 56:         while (count < 2_000_000) {
> 57:             new CompletableFuture<>().completeOnTimeout(null, 12, TimeUnit.HOURS).completeExceptionally(new RuntimeException("This is fine"));
> 58:             ++count;

Doing 2m iterations vs. original test to run for 10s is fine, assuming there is a OOME with a 128Mb heap. If I were editing this test then I'd probably split the overly long lines to make future side-by-side diffs easier to look at.

-------------

PR: https://git.openjdk.org/jdk/pull/13059


More information about the core-libs-dev mailing list