Skip to content
Latchkey

Kotlin compile daemon terminated unexpectedly in CI

The Kotlin Gradle plugin compiles in a separate daemon process. When that process is killed (OOM killer, resource limit, or a crash), Gradle reports the daemon terminated and either falls back to in-process compilation or fails. On constrained CI runners this is usually a memory problem.

What this error means

The Kotlin compile task logs "Kotlin compile daemon is ready" then "Kotlin compile daemon terminated unexpectedly" or "Could not connect to Kotlin compile daemon", and the build slows down or fails.

Kotlin
w: Kotlin compile daemon terminated unexpectedly
Could not connect to Kotlin compile daemon, using non-daemon strategy.

Common causes

The daemon JVM ran out of memory and was killed

On a small runner the daemon exceeds its heap or the container memory limit, and the OS kills it, so Gradle loses the connection.

A stale or crashed daemon from a prior run

A leftover daemon on a reused self-hosted runner is in a bad state, so the new build cannot connect to it.

How to fix it

Raise the Kotlin daemon JVM memory

Give the daemon and Gradle enough heap in gradle.properties so the daemon is not killed under load.

gradle.properties
# gradle.properties
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g
kotlin.daemon.jvmargs=-Xmx2g

Fall back to in-process compilation on tiny runners

If memory is very tight, run the Kotlin compiler in the Gradle process instead of a separate daemon.

Terminal
./gradlew build -Dkotlin.compiler.execution.strategy=in-process

How to prevent it

  • Size kotlin.daemon.jvmargs and org.gradle.jvmargs for the runner memory.
  • Use runners with enough RAM for the Kotlin daemon plus Gradle.
  • Avoid reusing dirty self-hosted runners; start each job with a clean daemon state.

Frequently asked questions

What causes ""Kotlin compile daemon ... terminated""?
On a small runner the daemon exceeds its heap or the container memory limit, and the OS kills it, so Gradle loses the connection.
How do I fix "Kotlin compile daemon ... terminated"?
Give the daemon and Gradle enough heap in gradle.properties so the daemon is not killed under load.

Related guides

References

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