From 7426ae520c93fe4f129ceed5cd11d4962c4425b2 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 17 Nov 2019 15:43:43 -0800 Subject: [PATCH] Fix background job shutdown When a user calls sbt exit and there is an active background job, sbt may not exit cleanly. This was primarily because the background job service shutdown method depended on the StandardMain.executionContext which was closed before the background job service was shutdown. This was fixable by reordering the resource closing in StandardMain.runManaged. --- main/src/main/scala/sbt/Main.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main/src/main/scala/sbt/Main.scala b/main/src/main/scala/sbt/Main.scala index 274c023d4..6337d1e59 100644 --- a/main/src/main/scala/sbt/Main.scala +++ b/main/src/main/scala/sbt/Main.scala @@ -126,15 +126,14 @@ object StandardMain { def runManaged(s: State): xsbti.MainResult = { val previous = TrapExit.installManager() try { + val hook = ShutdownHooks.add(closeRunnable) try { - val hook = ShutdownHooks.add(closeRunnable) - try { - MainLoop.runLogged(s) - } finally { - hook.close() - () - } - } finally DefaultBackgroundJobService.backgroundJobService.shutdown() + MainLoop.runLogged(s) + } finally { + try DefaultBackgroundJobService.backgroundJobService.shutdown() + finally hook.close() + () + } } finally TrapExit.uninstallManager(previous) }