Skip to content

Shutdown the runtime only when unforked#4234

Merged
djspiewak merged 1 commit into
typelevel:series/3.6.xfrom
armanbilge:fix/shutdown-runtime-unforked
Jan 11, 2025
Merged

Shutdown the runtime only when unforked#4234
djspiewak merged 1 commit into
typelevel:series/3.6.xfrom
armanbilge:fix/shutdown-runtime-unforked

Conversation

@armanbilge

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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