Skip to content
Latchkey

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

  1. Reduce the worker or maxWorkers count so each worker has more memory.
  2. Re-run with the lower parallelism.
GitHub Actions
- run: jest --maxWorkers=2

Raise the worker memory cap

  1. Increase maxOldGenerationSizeMb in the worker resourceLimits.
  2. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →