Bazel server out of memory / OOM in CI
The Bazel server (a JVM) or the runner exhausted memory while loading a large graph or running many actions at once. The build dies abruptly, sometimes killing the server.
What this error means
You see "java.lang.OutOfMemoryError: Java heap space", a server crash, or the OS killing the bazel process. Large monorepos with deep dependency graphs are most affected.
java.lang.OutOfMemoryError: Java heap space
ERROR: Bazel crashed due to an internal error. Printing stack trace:
FATAL: bazel server out of memory, exitingCommon causes
JVM heap too small for the graph
Loading and analyzing a very large dependency graph exceeds the default JVM heap.
Too many concurrent actions
High --jobs concurrency with memory-heavy actions exhausts runner RAM.
Runner has insufficient memory
A small CI instance cannot hold the working set of a large monorepo build.
How to fix it
Raise the JVM heap and cap concurrency
- Give the Bazel server more heap and reduce parallel jobs to fit memory.
# .bazelrc
startup --host_jvm_args=-Xmx8g
build --jobs=4Use a larger runner
- Move the build to a runner with more RAM so the graph and actions fit.
How to prevent it
- Self-healing managed runners like Latchkey auto-retry transient OOM-killed jobs, and larger runners give heavy monorepo builds the memory headroom Bazel needs.