[2.x] fix: Cleanup child processes on sbt exit (#8532)

When using fork := true, sbt spawns child processes that may become
stale if cancelled. Previously, these processes were not cleaned up
when running the exit command.

This fix adds RunningProcesses.killAll() to the shutdown hook so that
all tracked forked processes are terminated when sbt exits.

Fixes #7468
This commit is contained in:
MkDev11 2026-01-14 15:57:50 -05:00 committed by GitHub
parent 1ed08f0034
commit b58c0fb37f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 1 deletions

View File

@ -29,7 +29,7 @@ import sbt.internal.server.{ BuildServerProtocol, NetworkChannel }
import sbt.internal.util.Terminal.hasConsole
import sbt.internal.util.Types.{ const, idFun }
import sbt.internal.util.complete.Parser
import sbt.internal.util.{ Terminal as ITerminal, * }
import sbt.internal.util.{ RunningProcesses, Terminal as ITerminal, * }
import sbt.io.*
import sbt.io.syntax.*
import sbt.util.{ Level, Logger, Show }
@ -221,6 +221,7 @@ object StandardMain {
})
private val closeRunnable = () => {
RunningProcesses.killAll()
exchange.shutdown()
pool.foreach(_.shutdownNow())
}