Node "Worker terminated due to reaching memory limit" in CI - Fix Worker OOM
This error means a worker_thread exceeded its resourceLimits memory cap and Node terminated it. Test runners and parallel builds spawn such workers.
What this error means
A test or build using workers fails in CI with Error: Worker terminated due to reaching memory limit: JS heap out of memory, killing one of the parallel workers.
node
Error: Worker terminated due to reaching memory limit:
JS heap out of memory
at Worker.[kOnExit] (node:internal/worker:295:26)
at Worker.<computed>.onexit (node:internal/worker:216:20) {
code: 'ERR_WORKER_OUT_OF_MEMORY'
}Common causes
Too many workers competing for memory
A high worker count (test parallelism) divides the runner memory thin, so each worker is easily OOM-killed.
A worker resourceLimits cap set too low
maxOldGenerationSizeMb on the worker is below what the workload needs.
How to fix it
Lower worker concurrency
- Reduce the worker or maxWorkers count so each worker has more memory.
- Re-run with the lower parallelism.
GitHub Actions
- run: jest --maxWorkers=2Raise the worker memory cap
- Increase maxOldGenerationSizeMb in the worker resourceLimits.
- Keep the total within runner memory.
JavaScript
new Worker('./task.js', { resourceLimits: { maxOldGenerationSizeMb: 1024 } });How to prevent it
- Tune worker count to available memory and right-size worker heaps. On Latchkey, larger managed runners give parallel workers more headroom and transient OOM-kills are auto-retried.
Related guides
Node "FATAL ERROR: Reached heap limit Allocation failed" in CI - Fix the OOMFix the Node.js "FATAL ERROR: Reached heap limit Allocation failed" out-of-memory crash in CI by raising the…
Node "Segmentation fault" from a Native Addon in CI - Diagnose the CrashFix Node.js segmentation faults from a native addon in CI by rebuilding the addon for the runner, upgrading i…
Node "Timeout - Async callback was not invoked" in CI - Fix the Hanging TestFix the "Timeout - Async callback was not invoked within the timeout" test error in CI by resolving the pendi…