jest: Memory leak in jest-circus

🐛 Bug Report

When using jest-circus, an obvious memory leak and gradual slowdown occurs.

$ node --expose-gc ./node_modules/.bin/jest --logHeapUsage --runInBand funky
 PASS  tests/funky-36.test.js (20 MB heap size)
 PASS  tests/funky-86.test.js (22 MB heap size)
 PASS  tests/funky-28.test.js (24 MB heap size)
...
 PASS  tests/funky-56.test.js (195 MB heap size)
 PASS  tests/funky-24.test.js (197 MB heap size)
 PASS  tests/funky-30.test.js (199 MB heap size)
 PASS  tests/funky-52.test.js (201 MB heap size)

To Reproduce

100 identical tests with jest-circus/runner.

describe('funky-10.test', () => {
    test('funky-10', async () => {
        expect(1).toEqual(1);
    });
});

jest.config:

testRunner: require.resolve('jest-circus/runner')

Expected behavior

Same 100 tests without jest-circus/runner.

$ node --expose-gc ./node_modules/.bin/jest --logHeapUsage --runInBand funky
 PASS  tests/funky-36.test.js (17 MB heap size)
 PASS  tests/funky-40.test.js (17 MB heap size)
 PASS  tests/funky-28.test.js (17 MB heap size)
...
 PASS  tests/funky-18.test.js (17 MB heap size)
 PASS  tests/funky-87.test.js (17 MB heap size)
 PASS  tests/funky-89.test.js (17 MB heap size)

Link to repl or repo (highly encouraged)

https://github.com/dylang/jest-circus-memory-leak-repo

Run npx envinfo --preset jest

 System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 10.8.0 - ~/.nvm/versions/node/v10.8.0/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.8.0/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 15 (13 by maintainers)

Most upvoted comments

Here’s a PR for graceful-fs: https://github.com/isaacs/node-graceful-fs/pull/137

This PR fixes the issue in my repro repo at https://github.com/dylang/jest-circus-memory-leak-repo

HOWEVER, in my work repo that I can’t share here, the graceful-fs changes weren’t enough for jest-circus not to leak memory so I’m disabling it for now. I’ve spent more time than I intended already but I can look deeper if there are specific things I should try.

I’ve determined this is caused by graceful-fs.

https://github.com/isaacs/node-graceful-fs/issues/102

I have a fix locally and will create a PR to graceful-fs in the morning.