Skip to content
Latchkey

CI "Cannot allocate memory" - Fix ENOMEM on Runners

A syscall asked the kernel for memory and was refused with ENOMEM. Unlike a SIGKILL, the process survives to report the error - but the underlying cause is the same: not enough memory on the runner.

What this error means

A tool fails with Cannot allocate memory, OSError: [Errno 12], or mmap failed. The process is still alive to print the error, but it could not grow its heap, map a file, or spawn a thread because the allocation was denied.

CI log
fatal error: runtime: cannot allocate memory
# or
OSError: [Errno 12] Cannot allocate memory
# or
java.lang.OutOfMemoryError: unable to create new native thread

Common causes

The runner is out of usable RAM and swap

Other processes plus the failing one exhausted physical memory. With little or no swap on a CI runner, the next allocation is simply refused.

A cgroup memory limit blocks the allocation

A container or systemd cgroup with a memory.max/--memory limit will deny allocations once the cgroup reaches its ceiling, even when the host has free RAM.

Overcommit or address-space limits

A low vm.overcommit_memory setting, an ulimit -v (virtual memory) cap, or a 32-bit process can refuse a large mmap/malloc regardless of free RAM.

How to fix it

Check what memory is available

See real usage and any cgroup limit before changing resources.

Terminal
free -m
cat /sys/fs/cgroup/memory.max 2>/dev/null
ulimit -v

Add memory or raise the limit

  1. Run on a larger runner, or raise the container --memory ceiling.
  2. Lower the process’s own memory use (smaller heap, fewer threads, less parallelism).
  3. If ulimit -v is set too low, raise it for the step that needs it.

How to prevent it

  • Size runners so peak RAM stays comfortably under the limit.
  • Avoid hard ulimit -v caps unless you have a specific reason.
  • Cap thread pools and parallel workers to bound memory growth.

Frequently asked questions

What causes ""Cannot allocate memory""?
Other processes plus the failing one exhausted physical memory. With little or no swap on a CI runner, the next allocation is simply refused.
How do I fix "Cannot allocate memory"?
See real usage and any cgroup limit before changing resources.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

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