Skip to content
Latchkey

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, exiting

Common 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

  1. Give the Bazel server more heap and reduce parallel jobs to fit memory.
.bazelrc
# .bazelrc
startup --host_jvm_args=-Xmx8g
build --jobs=4

Use a larger runner

  1. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →