Skip to content
Latchkey

CI "Cannot allocate memory" on fork()

A fork() failed with ENOMEM: the kernel could not reserve memory for a new process. On a memory-tight runner this hits when overall usage (or a process/thread cap) is already near the limit.

What this error means

A command fails with fork: Cannot allocate memory or Resource temporarily unavailable, often while a build spawns many subprocesses. Freeing memory or using a larger runner clears it.

shell
bash: fork: Cannot allocate memory
make: *** [build] Error 1

Common causes

Memory is nearly exhausted

With little free RAM (and no swap headroom), the kernel cannot satisfy the fork allocation.

Too many concurrent processes

High build parallelism spawns more processes than the runner can back with memory.

How to fix it

Lower concurrency and free memory

Reduce parallel processes and reclaim RAM before the heavy step.

shell
free -h
make -j2          # instead of -j$(nproc)
# drop caches is host-only; prefer fewer workers in CI

Add memory headroom

  1. Run on a runner with more RAM.
  2. Raise a tight container --memory limit.
  3. Cap parallel jobs/tests to the runner size.

How to prevent it

  • Match build parallelism to runner cores and RAM.
  • Right-size memory for fork-heavy build systems.
  • Watch free -h in CI before heavy steps.

Frequently asked questions

What causes "fork: cannot allocate memory"?
With little free RAM (and no swap headroom), the kernel cannot satisfy the fork allocation.
How do I fix fork: cannot allocate memory?
Reduce parallel processes and reclaim RAM before the heavy step.
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