Skip to content

Release reusability token when suspendCancellableCoroutineReusable's … #3634

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

Merged
merged 3 commits into from
Mar 3, 2023

Conversation

qwwdfsad
Copy link
Collaborator

…block throws an exception

Otherwise, continuation instance is left in REUSABLE_CLAIMED state that asynchronous resumer awaits in an infinite spin-loop, potentially causing deadlock with 100% CPU consumption. Originally, the bug was reproduced on old (pre-#3020) implementation where this very pattern was encountered: it was possible to fail owner's invariant check right in the supplied 'block'. This is no longer the case, so the situation is emulated manually (but still is possible in production environments, e.g. when OOM is thrown). Also, suspendCancellableCoroutineReusable is removed from obsolete BroadcastChannel implementation.

Fixes #3613

…block throws an exception

Otherwise, continuation instance is left in REUSABLE_CLAIMED state that asynchronous resumer awaits in an infinite spin-loop, potentially causing deadlock with 100% CPU consumption.
Originally, the bug was reproduced on old (pre-#3020) implementation where this very pattern was encountered: it was possible to fail owner's invariant check right in the supplied 'block'.
This is no longer the case, so the situation is emulated manually (but still is possible in production environments, e.g. when OOM is thrown).
Also, suspendCancellableCoroutineReusable is removed from obsolete BroadcastChannel implementation.

Fixes #3613
@qwwdfsad
Copy link
Collaborator Author

Also filed #3635 to eventually address the issue in a more systematic and graceful manner

Comment on lines 248 to 249
* Note that this implementation always invokes [suspendCancellableCoroutineReusable],
* as we do not care about broadcasts performance -- they are already deprecated.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Note that this implementation always invokes [suspendCancellableCoroutineReusable],
* as we do not care about broadcasts performance -- they are already deprecated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, what did this comment mean? suspendCancellableCoroutineReusable is a slower internal version of suspendCancellableCoroutine that we use internally as a performance de-optimization, and now that BroadcastChannel is deprecated, we're free to make it fast, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this is just a miswording, asked Nikita to verify just in case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea was "it doesn't have non-suspending fast-path"

@qwwdfsad qwwdfsad merged commit 46765ed into develop Mar 3, 2023
@qwwdfsad qwwdfsad deleted the fix-infinite-spin-loop branch March 3, 2023 15:23
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.

2 participants