RFR: JDK-8303742: CompletableFuture.orTimeout leaks if the future completes exceptionally [v2]
Pavel Rappo
prappo at openjdk.org
Thu Mar 16 20:56:00 UTC 2023
On Thu, 16 Mar 2023 20:51:37 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:
>
> Update test/jdk/java/util/concurrent/CompletableFuture/CompletableFutureOrTimeoutExceptionallyTest.java
>
> Co-authored-by: Andrey Turbanov <turbanoff at gmail.com>
test/jdk/java/util/concurrent/CompletableFuture/CompletableFutureOrTimeoutExceptionallyTest.java line 44:
> 42: void testOrTimeoutWithCompleteExceptionallyDoesNotLeak() throws Exception {
> 43: var startTime = System.currentTimeMillis();
> 44: var testRunTime = Duration.ofSeconds(10).toMillis();
This "create completable futures in a loop for t seconds" seems a bit brittle. Would 10 or 20 seconds be enough for a typical test machine to fail with OOME? Could this be improved by requiring a minimum number of CF instances to be created? Maybe finishing when t seconds have elapsed _and_ n instances have been created.
Separately, as with any timeouts, consider a monotonic clock.
-------------
PR: https://git.openjdk.org/jdk/pull/13059
More information about the core-libs-dev
mailing list