Bazel server JVM OutOfMemoryError (heap) in CI
The Bazel server runs on a JVM, and analyzing a large build graph can exhaust its heap. When it does, Bazel crashes with an OutOfMemoryError from com.google.devtools.build.lib. Raise the server heap with --host_jvm_args=-Xmx.
What this error means
A build aborts with "java.lang.OutOfMemoryError: Java heap space" in a com.google.devtools.build.lib stack, sometimes after the server appears to hang.
FATAL: bazel crashed due to an internal error.
java.lang.OutOfMemoryError: Java heap space
at com.google.devtools.build.lib.skyframe...Common causes
The server heap is too small for the graph
A large monorepo graph needs more heap than the default the Bazel server starts with, so analysis exhausts it.
A memory-constrained CI runner
Small runners give the JVM little headroom, so the server hits the heap ceiling on builds that pass on larger machines.
How to fix it
Raise the Bazel server heap
Set the JVM max heap for the Bazel server with a startup flag in .bazelrc so it applies to every command.
startup --host_jvm_args=-Xmx4gUse a larger runner or trim analysis
- Move the job to a runner with more memory so the JVM has headroom.
- Reduce the analyzed set with narrower target patterns where possible.
- Re-run so analysis fits within the heap.
bazel --host_jvm_args=-Xmx6g build //foo/...How to prevent it
- Set --host_jvm_args=-Xmx in .bazelrc sized to your graph.
- Give CI runners enough memory for the Bazel server plus actions.
- Build narrower target patterns when the full graph is not needed.