Propagate fatal errors from async/cont callbacks - #4653
Open
arimu1 wants to merge 1 commit into
Open
Conversation
OutOfMemoryError and other fatal Throwables delivered via cont/async resume (including IO.fromCompletableFuture) completed as Outcome.Errored instead of crashing the process like IO.raiseError. Detect fatals in asyncContinueFailedR and the synchronous cont Get path, matching the Error/raiseError handling in the runloop. Fixes typelevel#4505
selormwalker
reviewed
Aug 7, 2026
selormwalker
left a comment
There was a problem hiding this comment.
Nice improvements! Ready for merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #4505
Fatal errors (
OutOfMemoryErrorand other non-UnsafeNonFatalthrowables) delivered through an async/cont resume callback were completed asOutcome.Erroredon the fiber instead of crashing the process. That differed fromIO.raiseError(fatal)and from fatals thrown insideIO.delay/IOthunks, which already callonFatalFailure.This shows up with
IO.fromCompletableFuturebecauseCompletableFuture.handlecatches the fatal and resumes withLeft(t), and also with a minimized form:Approach
Detect fatal errors as soon as the cont/async result is consumed by the runloop, matching the existing
Error/raiseErrorcase:asyncContinueFailedR— async resume withLeft(fatal)IOCont.Getwhen the callback already completed — synchronous cont completion withLeft(fatal)No change to
fromCompletableFutureitself: rethrowing insideCompletableFuture.handleis unnecessary once the fiber treats the resumed fatal correctly, and avoids leaving the cont suspended if the throw is mishandled on the CF thread.Prior attempt #4512 targeted a similar issue but was closed (hanging tests / abandoned). This PR only touches the fiber paths that consume the failure.
Testing
exit on fatal error from async_exit on fatal error from CompletableFuture(JVM)sbt ioAppTestsJVM/testOnly cats.effect.IOAppSpec— 28 examples, 0 failure (Temurin 21), including both new cases