question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak issue with jest

See original GitHub issue

What is the expected behavior? Node heap size shouldn’t grow in every test.

What is the actual behavior? Heap size increases after every test file.

With nock:

PASS  test/function-86.js (22 MB heap size)
PASS  test/function-75.js (22 MB heap size)
PASS  test/function-1.js (22 MB heap size)
PASS  test/function-43.js (26 MB heap size)
PASS  test/function-24.js (26 MB heap size)
...
PASS  test/function-48.js (133 MB heap size)
PASS  test/function-82.js (137 MB heap size)
PASS  test/function-87.js (137 MB heap size)
PASS  test/function-20.js (137 MB heap size)
PASS  test/function-79.js (140 MB heap size)

Test Suites: 100 passed, 100 total
Tests:       100 passed, 100 total
Snapshots:   0 total
Time:        25.506s, estimated 26s

Without nock:

PASS  test/function-86.js (19 MB heap size)
PASS  test/function-75.js (19 MB heap size)
PASS  test/function-1.js (19 MB heap size)
PASS  test/function-65.js (19 MB heap size)
PASS  test/function-96.js (19 MB heap size)
...
PASS  test/function-93.js (20 MB heap size)
PASS  test/function-61.js (20 MB heap size)
PASS  test/function-49.js (20 MB heap size)
PASS  test/function-87.js (20 MB heap size)
PASS  test/function-79.js (20 MB heap size)

Test Suites: 100 passed, 100 total
Tests:       100 passed, 100 total
Snapshots:   0 total
Time:        27.079s

How to reproduce the issue

Even a single require/import of nock seems to cause the issue.

Minimal test case: https://github.com/juhosuominen/jest-nock-memory-leak

Versions

Software Version(s)
Nock 11.7.0
Node 11.15.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
RedTncommented, Jul 28, 2022

This still seems to be an issue, though I can confirm that when I use node 11.15.0 and jest ^26 that there is no leak. As soon as I upgrade to node 16 (16.10.0) this is an issue again https://github.com/nock/nock/issues/2383

Read more comments on GitHub >

github_iconTop Results From Across the Web

Your Jest Tests are Leaking Memory
Jest is designed in a way that makes memory leaks likely if you're not actively trying to squash them. For many test suites...
Read more >
Finding the cause of a memory leak in Jest tests
Memory leaks can be nasty and pretty hard to find. We found that the hard way. We should always make sure to clean...
Read more >
Jest memory leak issue - Stack Overflow
I am running jest unit and integrations tests on my NodeJS api, I am facing some issue with possible memory leak. I tried...
Read more >
Jest Memory Leaks - Some Lessons Learnt - Lukas Spiss
There seems to be a bug, introduced with Node v16.11, causing memory leaks with Jest. While this bug is certainly putting my Node...
Read more >
[Bug]: Memory consumption issues on Node JS 16.11.0+ ...
Since Jest calls global.gc() when Garbage Collector is exposed and --logHeapUsage flag is present, the memory usage should be stable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found