[2.x] fix: Prevent sbt test from hanging when forked process crashes (#8536)

When a forked test process crashes (e.g., due to UnsupportedClassVersionError),
sbt would hang forever waiting for test results. This happened because
notifyExit only completed the promise with success, regardless of the
exit code.

This fix checks the exit code and fails the promise if the process
exited with a non-zero code, allowing sbt to properly report the failure
and exit.

Fixes #7429
This commit is contained in:
MkDev11 2026-01-14 21:54:17 -05:00 committed by GitHub
parent b58c0fb37f
commit fb53925fb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -211,7 +211,11 @@ private class React(
case NonFatal(_) => ()
override def notifyExit(p: Process): Unit =
if !process.isAlive then promise.success(process.exitValue())
if !process.isAlive && !promise.isCompleted then
val exitCode = process.exitValue()
if exitCode != 0 then
promise.failure(new RuntimeException(s"Forked test process exited with code $exitCode"))
else promise.success(exitCode)
def processNotification(o: JsonObject): Unit =
val method = o.getAsJsonPrimitive("method").getAsString()