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

Prevent StackOverflowError in CompletableFuture.asDeferred and proper… #2731

Merged
merged 4 commits into from May 27, 2021

Conversation

qwwdfsad
Copy link
Member

…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

…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
class FutureAsDeferredUnhandledCompletionExceptionTest : TestBase() {

// This is a separate test in order to avoid interference with uncaught exception handlers in other tests
private val exceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: wouldn't it be more symmetrical if exceptionHandler was also initialized in setUp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it more concise to initialize in-place everything that could be initialized in-place, [opinionated] it reads better and is easier to reason about

integration/kotlinx-coroutines-jdk8/src/future/Future.kt Outdated Show resolved Hide resolved
qwwdfsad and others added 2 commits May 27, 2021 17:51
Co-authored-by: dkhalanskyjb <52952525+dkhalanskyjb@users.noreply.github.com>
@qwwdfsad qwwdfsad merged commit 937180f into develop May 27, 2021
@qwwdfsad qwwdfsad deleted the futures-fix branch May 27, 2021 14:52
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this pull request 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants