Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent StackOverflowError in CompleteableFuture.asDeferred #2730

Closed
qwwdfsad opened this issue May 26, 2021 · 0 comments
Closed

Silent StackOverflowError in CompleteableFuture.asDeferred #2730

qwwdfsad opened this issue May 26, 2021 · 0 comments
Labels

Comments

@qwwdfsad
Copy link
Member

@Test
fun testStackOverflow() = runTest {
    val future = CompletableFuture<Int>()
    val completed = AtomicLong()
    val count = 10000L
    for (i in 0 until count) {
        launch(Dispatchers.Default) {
            future.asDeferred().await()
            completed.incrementAndGet()
        }
    }
    future.complete(1)
    withTimeout(60_000) {
        coroutineContext.job.children.toList().joinAll()
        assertEquals(count, completed.get())
    }
}
@qwwdfsad qwwdfsad added the bug label May 26, 2021
qwwdfsad added a commit that referenced this issue May 26, 2021
…ly report exceptions from completion handlers

    * It turned out that 'cancel' on completed future tries to help and invoke 'whenComplete' handlers that also invoke 'cancel' on the very same future
    * Use top-level exception handler as a last resort to deliver an exception

Fixes #2730
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
Kotlin#2731)

Prevent StackOverflowError in CompletableFuture.asDeferred and properly report exceptions from completion handlers

* It turned out that 'cancel' on completed future tries to help and invoke 'whenComplete' handlers that also invoke 'cancel' on the very same future
* Use top-level exception handler as a last resort to deliver an exception

Fixes Kotlin#2730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant