-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
🐛 Bug Report
I've been dealing with out of memory and/or EAGAIN errors for a few months now, ever since I upgraded to Jest 20 & started using the multi-project runner. I've been running with --runInBand
as a workaround.
I believe this is happening because Jest creates too many worker processes when building the haste-map cache if you have multiple projects & maxWorkers > 1.
- For each project being tested by jest, jest creates a haste map. See https://github.com/facebook/jest/blob/master/packages/jest-core/src/cli/index.ts#L120-L132
- For each haste map, jest creates a worker pool with
maxWorkers
workers. See https://github.com/facebook/jest/blob/master/packages/jest-haste-map/src/index.ts#L736-L740
This means that instead of restricting the number of workers to maxWorkers
overall, it restricts it to maxWorkers
per project (maxWorkers * numProjects
). In my case that's 226 projects and 8 cpu cores, so 8 * 226 = 1808
worker processes. When I run jest it chugs for about a minute, then either runs out of memory or hits the OS's process limit.
Note: this is only a problem while it is building the cache. Once the cache is built, jest will start actually testing the files and does so with the right number of workers.
To Reproduce
You should be able to reproduce this in any multi-project setup. Just run the tests in multi-project mode and watch how many worker processes get spawned while it's building the haste-map cache, before the tests start running.
I was able to reproduce it with the jest repo:
- Clone the jest repo
- yarn install
- open the mac os "Activity Monitor" (or an equivalent process monitor on another platform) and filter for node processes
- yarn jest --clearCache
- yarn jest
- watch how many new node processes show up in the activity monitor
When I did this with the jest, I saw approximately 25 worker processes running. I expected no more than 8.
Expected behavior
It should never spawn more than maxWorkers
processes.
Link to repl or repo (highly encouraged)
See above. I was able to reproduce this with the jest repo.
envinfo
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 12.9.1 - ~/.nvm/versions/node/v12.9.1/bin/node
Yarn: 1.19.1 - ~/.nvm/versions/node/v12.9.1/bin/yarn
npm: 6.10.2 - ~/.nvm/versions/node/v12.9.1/bin/npm