cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Fix fatal error propagation in async operations

Open najuna-brian opened this issue 2 months ago • 7 comments

Description

Fixes #4505

Fixed fatal error propagation in async operations so fatal errors crash the JVM instead of being caught and wrapped.

Changes

kernel/jvm/src/main/scala/cats/effect/kernel/AsyncPlatform.scala: Added fatal error detection in fromCompletableFuture to re-throw fatal errors instead of wrapping them core/shared/src/main/scala/cats/effect/IO.scala: Removed IO.delay() wrapper in IO.async_ to allow fatal errors to propagate during callback registration

Why both changes?

  • fromCompletableFuture uses CompletableFuture.handle() which catches all exceptions, including fatal ones
  • async_ had IO.delay() wrapper catching fatal errors during callback registration

Testing

  • Added tests for both fromCompletableFuture and async_ fatal error scenarios
  • All tests pass (JVM tests, kernel tests)
  • Eliminates need for .onError(_ => IO.unit) workaround mentioned in the issue

najuna-brian avatar Oct 17 '25 08:10 najuna-brian

Hi @armanbilge, @durban

Would you mind taking a look at this when you have a moment?

Thanks!

najuna-brian avatar Oct 17 '25 09:10 najuna-brian

Since this is a bug fix, you can target the series/3.6.x branch

Thanks for the review and guidance. Just learnt about all these upstream branches now :blush:

najuna-brian avatar Oct 21 '25 18:10 najuna-brian

Hello @armanbilge I guess i will have to wait for this PR t be merged and then I can proceed.. Thank you

najuna-brian avatar Oct 26 '25 05:10 najuna-brian

@najuna-brian https://github.com/typelevel/cats-effect/pull/4518 is merged now, thanks for your patience! You can merge the latest series/3.6.x into your branch.

armanbilge avatar Oct 27 '25 14:10 armanbilge

@najuna-brian it looks like one of the tests you added is hanging in the CI. Are you able to run the tests locally?

Yes true they keep hanging, Though I am not sure of how to solve that.

najuna-brian avatar Nov 04 '25 07:11 najuna-brian

@najuna-brian #4518 is merged now, thanks for your patience! You can merge the latest series/3.6.x into your branch.

Thank you @armanbilge I will please proceed now

najuna-brian avatar Nov 04 '25 07:11 najuna-brian

Yes true they keep hanging, Though I am not sure of how to solve that.

You should start by identifying which test is hanging (a low-tech way to do this is to comment out tests until you figure out which one it is). Then, once you know which test it is, you can try reverting some of your changes to identify which change you made may cause it to hang.

armanbilge avatar Nov 04 '25 17:11 armanbilge