Maven Surefire "The forked VM terminated without saying goodbye"
Surefire runs tests in a forked JVM. This error means that JVM died abruptly - no clean shutdown handshake. On CI it is almost always the OOM killer terminating the forked process, or a test that called System.exit.
What this error means
The test phase fails with The forked VM terminated without properly saying goodbye. VM crash or System.exit called?, often quoting the exact command Surefire used to launch the forked JVM. There is no assertion failure - the process vanished.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test (default-test) on
project app: The forked VM terminated without properly saying goodbye.
VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /workspace && /opt/jdk/bin/java -jar ...surefirebooter.jarCommon causes
Forked test JVM OOM-killed
The forked JVM’s heap plus the Maven process exceeded the runner’s RAM, so the kernel SIGKILLed the test JVM. It dies before it can report back, producing this exact message.
A test (or native code) crashed or called System.exit
A test invoking System.exit, or a native library segfaulting (a hs_err_pid dump appears), terminates the forked JVM uncleanly.
How to fix it
Cap the forked test heap to fit the runner
Set Surefire’s forked JVM args so the test heap, plus Maven, fits in RAM.
<configuration>
<argLine>-Xmx1g -XX:MaxMetaspaceSize=256m</argLine>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>Reduce parallelism or find the crash
- Lower
forkCountso fewer test JVMs run at once on a small runner. - Check for a
hs_err_pid*.log(a JVM crash dump) or a native-library segfault. - Grep tests for a stray
System.exitcall that kills the forked VM.
How to prevent it
- Set Surefire
<argLine>heap relative to the runner RAM. - Bound
forkCountso concurrent test JVMs do not exhaust memory. - Never call
System.exitin tests; assert and return instead.