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

Shutdown the runtime only when unforked #4234

Merged

Conversation

armanbilge
Copy link
Member

It's already explained in the code comment: shutting down the runtime is really only relevant for unforked scenarios.

// Clean up after ourselves, relevant for running IOApps in sbt,
// otherwise scheduler threads will accumulate over time.
runtime.shutdown()

By not aggressively shutting down the runtime in the shutdown handler, we fix some gotchas e.g. deadlock if you attempted to execute System.exit on the runtime.

Comment on lines 219 to 221
case t =>
runtime.shutdown()
queue.clear()
queue.put(t)
Copy link
Member Author

Choose a reason for hiding this comment

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

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))
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@armanbilge armanbilge added this to the v3.6.0 milestone Jan 11, 2025
@djspiewak djspiewak merged commit eb1f3e3 into typelevel:series/3.6.x Jan 11, 2025
29 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants