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

Andrey Turbanov aturbanov at openjdk.org
Thu Mar 16 20:15:45 UTC 2023


On Thu, 16 Mar 2023 13:37:10 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

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

> 43:         var startTime = System.currentTimeMillis();
> 44:         var testRunTime = Duration.ofSeconds(10).toMillis();
> 45:         while((System.currentTimeMillis() - startTime) < testRunTime) {

Suggestion:

        while ((System.currentTimeMillis() - startTime) < testRunTime) {

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

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


More information about the core-libs-dev mailing list