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

[prelude][core][stm] fix issue with preemption in nested async computations #927

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

fwbrasil
Copy link
Collaborator

Fixes #925

The issue is more generic than the use with STM. Kyo's kernel uses a safepoint mechanism to preempt execution on any step of a computation. kyo-core extends this mechanism by setting the safepoint interceptor to the current fiber to handle preemption. For example, if the fiber is interrupted, the next safepoint will trigger preemption to stop the computation and clear finalizers. The other possibility is the scheduler itself triggering preemption due to the fiber taking more than the configured time slice (10ms by default) so it can return to the execution queue to provide fairness.

The cause of the bug is the interceptor propagating to nested async computations. This PR fixes Safepoint.eval, which is called from the pending type's eval, to clear the interceptor since the eval operation itself can't be delayed and has to return a concrete value. Even if the outer async computation is preempted, the nested one needs to execute to completion.

@@ -87,6 +87,9 @@ sealed private[kyo] class IOTask[Ctx, E, A] private (

private inline def nullResult = null.asInstanceOf[A < Ctx & Async & Abort[E]]

override def toString =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to help with debugging

@fwbrasil fwbrasil merged commit 79a5a07 into main Dec 16, 2024
3 checks passed
@fwbrasil fwbrasil deleted the preemption-nested branch December 16, 2024 22:46
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.

Infinite loop with STM + unhandled exception + toFuture/fromFuture
2 participants