-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix module registry memory leak. #8282
Fix module registry memory leak. #8282
Conversation
🎉🎉🎉 Circus CI no longer fails with an OOM error, which means this has definitely made an impact. Just need a sanity check on the behavior change and if it makes sense. In the case where we want to preserve the old behavior (I still think it's a bug), it can be done in a way that doesn't create a large memory leak. @cpojer take a look if you have a moment, maybe you can confirm it's a bug for me? |
Codecov Report
@@ Coverage Diff @@
## master #8282 +/- ##
=======================================
Coverage 62.13% 62.13%
=======================================
Files 266 266
Lines 10664 10664
Branches 2590 2590
=======================================
Hits 6626 6626
Misses 3448 3448
Partials 590 590
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so awesome!
Changelog? 😀
I agree. Hopefully nobody (unwittingly) relied on getting old versions of modules after a reset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work identifying this ❤️
Also cc @dubzzz |
This is great! Memory leaks are the worst. |
@scotthovestadt can we get a release with this PR? Our tests are broken in CI due to memory leaks and it would be nice to be able to test this. |
@peterdemartini Yes, soon! There will be a release within a week. Please report back and let me know if this has solved it for you after the release. |
Any updates concerning the release @scotthovestadt ? 🙏 |
Please release 🙏 My Jest integration tests eat 10 GB ... :/ |
Oh. This has been released with 24.8 and I have 24.8. Oh my dear. 10 GB ! |
This was released as part of jest 24.8.0 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This leak is caused by this line:
https://github.com/facebook/jest/blob/01044dabf2253287a5a84e6a87b8505b559e9257/packages/jest-runtime/src/index.ts#L693
The
moduleRegistry
is preserved in the closure and never GC'd, along with all modules within the registry, making it a pretty nasty memory leak. I'm fairly certain it's also a bug fix: when you reset the registry, this reference to the registry continued referencing the old version. That doesn't make sense after a reset.This code is now a map and easy to clear but until very recently it was a normal
Object
which explains why it was 'cleared' in this way.Memory Impact
command:
yarn jest --logHeapUsage --w=1 packages/
--expose-gc
enabled to trigger gc manually after each test for accurate readings on the leakwithout circus:
295 MB -> 262 MB (11% savings)
with circus:
848 MB -> 762 MB (10% savings)
Test plan