From 977958e2c8862b5e653ea44dfcaaeb882956ca60 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 11 Jan 2025 03:19:16 +0000 Subject: [PATCH] Shutdown the runtime only when unforked --- core/jvm/src/main/scala/cats/effect/IOApp.scala | 5 ++--- tests/jvm/src/main/scala/catseffect/examplesplatform.scala | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/jvm/src/main/scala/cats/effect/IOApp.scala b/core/jvm/src/main/scala/cats/effect/IOApp.scala index 1b739538e6..e7cc0b0552 100644 --- a/core/jvm/src/main/scala/cats/effect/IOApp.scala +++ b/core/jvm/src/main/scala/cats/effect/IOApp.scala @@ -217,7 +217,6 @@ trait IOApp { IOApp.this.reportFailure(t).unsafeRunAndForgetWithoutCallback()(runtime) case t => - runtime.shutdown() queue.clear() queue.put(t) } @@ -504,7 +503,7 @@ trait IOApp { // Clean up after ourselves, relevant for running IOApps in sbt, // otherwise scheduler threads will accumulate over time. - runtime.shutdown() + if (!isForked) runtime.shutdown() } val hook = new Thread(() => handleShutdown()) @@ -527,7 +526,7 @@ trait IOApp { case ec: ExitCode => // Clean up after ourselves, relevant for running IOApps in sbt, // otherwise scheduler threads will accumulate over time. - runtime.shutdown() + if (!isForked) runtime.shutdown() if (ec == ExitCode.Success) { // Return naturally from main. This allows any non-daemon // threads to gracefully complete their work, and managed diff --git a/tests/jvm/src/main/scala/catseffect/examplesplatform.scala b/tests/jvm/src/main/scala/catseffect/examplesplatform.scala index 6f2a553c88..fddb6e17e1 100644 --- a/tests/jvm/src/main/scala/catseffect/examplesplatform.scala +++ b/tests/jvm/src/main/scala/catseffect/examplesplatform.scala @@ -35,8 +35,7 @@ package examples { override protected def runtimeConfig = super.runtimeConfig.copy(shutdownHookTimeout = Duration.Zero) - val run: IO[Unit] = - IO.blocking(System.exit(0)).uncancelable + val run: IO[Unit] = IO(System.exit(0)) } object FatalErrorUnsafeRun extends IOApp {