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.
bazel
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
# .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.
Related guides
Bazel remote cache connection failed (transient) in CIFix Bazel remote cache connection failures in CI. A transient network or auth blip to the gRPC/HTTP cache bac…
Bazel "Build did NOT complete successfully" in CIFix Bazel "ERROR: Build did NOT complete successfully" in CI. This summary line follows the real failure - re…
Nx out of memory building project graph in CIFix Nx out-of-memory while constructing the project graph in CI. A large workspace exceeded the Node heap dur…