Shutdown the runtime only when unforked#4234
Merged
djspiewak merged 1 commit intoJan 11, 2025
Merged
Conversation
armanbilge
commented
Jan 11, 2025
Comment on lines
219
to
221
| case t => | ||
| runtime.shutdown() | ||
| queue.clear() | ||
| queue.put(t) |
Member
Author
There was a problem hiding this comment.
We don't have access to isForked here. But, I think this particular case doesn't matter, because t is a fatal exception, and point of fatal exceptions in that they may leave the JVM in an inconsistent state (such as stuff not being shutdown/closed). Furthermore it may never have been safe to attempt shutdown here anyway—we don't entirely control this shutdown code, so we couldn't be certain it's not allocating.
|
|
||
| val run: IO[Unit] = | ||
| IO.blocking(System.exit(0)).uncancelable | ||
| val run: IO[Unit] = IO(System.exit(0)) |
Member
Author
There was a problem hiding this comment.
Restores this test to the original state*, now that we fixed this gotcha.
* The original test had uncancelable and I'm not sure why, since I don't think it does anything.
djspiewak
approved these changes
Jan 11, 2025
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.
It's already explained in the code comment: shutting down the runtime is really only relevant for unforked scenarios.
cats-effect/core/jvm/src/main/scala/cats/effect/IOApp.scala
Lines 505 to 507 in a49a028
By not aggressively shutting down the runtime in the shutdown handler, we fix some gotchas e.g. deadlock if you attempted to execute
System.exiton the runtime.