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.
This commit is contained in:
Ethan Atkins 2019-11-17 15:43:43 -08:00
parent 8d26bc73b4
commit 7426ae520c
1 changed files with 7 additions and 8 deletions

View File

@ -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)
}