CI "bash: fork: Cannot allocate memory" - Out of RAM to Fork
By Kaveh Alemi·Latchkey
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.
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
Move the job to a runner with more RAM.
Reduce parallelism and cap language heaps so the working set is smaller.
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.