Skip to content
Latchkey

CI "bash: fork: Cannot allocate memory" - Out of RAM to Fork

The shell tried to fork() a child and the kernel refused with ENOMEM. Unlike an EAGAIN (process-limit) fork failure, this one is specifically about memory - there was not enough free RAM to back a new process.

What this error means

Bash prints fork: Cannot allocate memory and commands stop launching. It often cascades - once the shell cannot fork, almost every subsequent command fails the same way. Re-running on a runner with more RAM passes unchanged.

CI log
bash: fork: Cannot allocate memory
./build.sh: line 40: /usr/bin/node: Cannot allocate memory

Common causes

The runner is out of usable RAM

Forking a process needs memory for its page tables and stack. Under heavy memory pressure the kernel cannot satisfy that allocation and returns ENOMEM, so fork() fails outright.

A low overcommit setting refused the allocation

With vm.overcommit_memory=2 (strict) and little headroom, the kernel denies the fork even when some memory looks free, because it will not promise memory it cannot guarantee.

How to fix it

Check available memory

See real RAM and swap usage before changing the runner.

Terminal
free -m
cat /proc/sys/vm/overcommit_memory

Add memory or lower peak usage

  1. Move the job to a runner with more RAM.
  2. Reduce parallelism and cap language heaps so the working set is smaller.
  3. Fix any process/memory leak that drives the runner toward exhaustion.

How to prevent it

  • Right-size runners so peak RAM stays under the ceiling.
  • Cap thread pools and parallel workers to bound memory growth.
  • Watch memory high-water marks so you catch growth before forks fail.

Frequently asked questions

What causes ""bash: fork: Cannot allocate memory""?
Forking a process needs memory for its page tables and stack. Under heavy memory pressure the kernel cannot satisfy that allocation and returns ENOMEM, so fork() fails outright.
How do I fix "bash: fork: Cannot allocate memory"?
See real RAM and swap usage before changing the runner.
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