RFR: JDK-8303742: CompletableFuture.orTimeout leaks if the future completes exceptionally [v3]
Jaikiran Pai
jpai at openjdk.org
Fri Mar 17 06:37:21 UTC 2023
On Thu, 16 Mar 2023 21:25:44 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:
>
> Making the test for orTimeout+completeExceptionally only based on iterations and not duration.
Hello Viktor, the changes look good to me. Looking at the code, I see that this issue will also affect the `completeOnTimeout(...)` method on the `CompletableFuture`. Would you want to enhance the test to include a test for this method too? The following test method which tests this `completeOnTimeout()` reproduces the leak (and thus the OOM) without your fix:
@Test
void testCompleteOnTimeoutWithCompleteExceptionallyDoesNotLeak() {
var count = 0L;
while(count < 2_000_000) {
new CompletableFuture<>().completeOnTimeout(null, 12, TimeUnit.HOURS).completeExceptionally(new RuntimeException("This is fine"));
++count;
}
}
-------------
PR: https://git.openjdk.org/jdk/pull/13059
More information about the core-libs-dev
mailing list