Skip to content
Latchkey

Gradle "Gradle Test Executor finished with non-zero exit" in CI

Gradle runs tests in forked worker JVMs. "Process 'Gradle Test Executor N' finished with non-zero exit value M" means a worker JVM died unexpectedly - frequently an OOM kill (exit 137) on a constrained runner, a System.exit, or a native crash.

What this error means

The test task fails with Process 'Gradle Test Executor 2' finished with non-zero exit value 137. Exit 137 = SIGKILL (OOM); other codes point to native crashes or System.exit.

gradle
> Task :test FAILED
Process 'Gradle Test Executor 2' finished with non-zero exit value 137
> There were failing tests. See the report at: .../build/reports/tests/test/index.html

Common causes

Test worker OOM-killed (exit 137)

Worker heap/Metaspace plus container overhead exceeds runner memory; the kernel kills the worker with SIGKILL (137). This is the transient, capacity-driven case.

System.exit or native crash in a test

A test calling System.exit, or a JNI/native crash, also terminates the worker with a non-zero code deterministically.

How to fix it

Bound worker memory and parallelism

Set per-worker heap and limit maxParallelForks so concurrent workers fit in RAM.

build.gradle
test {
  maxParallelForks = 1
  forkEvery = 100
  maxHeapSize = '1536m'
  jvmArgs '-XX:MaxMetaspaceSize=384m'
}

Distinguish OOM from a code crash

  1. Exit 137 = OOM kill; reduce parallel forks or use a larger runner.
  2. Other codes: look for System.exit in tests or an hs_err_pid*.log native crash file.
  3. Open the HTML test report to see which class was running when the worker died.

How to prevent it

  • Size worker heap and maxParallelForks to the runner, forbid System.exit in tests, and run heavy suites on larger runners.

Frequently asked questions

What causes ""Process 'Gradle Test Executor N' finished with non-zero exit value""?
Worker heap/Metaspace plus container overhead exceeds runner memory; the kernel kills the worker with SIGKILL (137). This is the transient, capacity-driven case.
How do I fix "Process 'Gradle Test Executor N' finished with non-zero exit value"?
Set per-worker heap and limit maxParallelForks so concurrent workers fit in RAM.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card