Skip to content
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

jests async wrapper leaks memory #8984

Closed
Swatinem opened this issue Sep 26, 2019 · 7 comments
Closed

jests async wrapper leaks memory #8984

Swatinem opened this issue Sep 26, 2019 · 7 comments

Comments

@Swatinem
Copy link

🐛 Bug Report

Possibly related to: #6814 and other reports of memory leaks…

I do have quite severe memory leaks, because one of our modules is super big (it imports a translation dictionary in multiple languages).
Each test file which imports that module blows up jests memory usage by ~20M.

While debugging the memory leak, I noticed that the translation dictionary is kept alive through jests asyncJestTest, which holds onto the closure fn.

Bildschirmfoto von 2019-09-26 15-20-30

I tried just unsetting fn after calling it, which worked for the asyncJestTest, but was failing for asyncJestLifecycle for some reason.

    TypeError: Cannot read property 'call' of null

      at Object.asyncJestLifecycle (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:51:37)

Oh, I get it… most likely because those lifecycles are called multiple times, haha.

To Reproduce

Steps to reproduce the behavior:

Use async functions for tests and lifecycle hooks that reference large objects :-)

Expected behavior

Jest should not leak! It should clean up all the async functions properly when a test file is finished.

Link to repl or repo (highly encouraged)

envinfo

@thymikee
Copy link
Collaborator

I wonder if it also happens with jest-circus? https://github.com/facebook/jest/tree/master/packages/jest-circus

@Swatinem
Copy link
Author

Haven’t tried it yet, will do so tomorrow. Lets see how easy it is to integrate… We have a quite complex setup, also browsing through the issues, I’m not sure how production ready it already is?

@thymikee
Copy link
Collaborator

It is production ready, but has differences from jasmine

@Swatinem
Copy link
Author

Just tried jest-circus, and it also leaks per-testfile. I haven’t looked at the memory profile itself to see where/why all the memory is retained, so it could as well be for some other reason.
All-in-all, the memory usage with jest-circus is even worse. Whereas our memory usage peaks at ~880M with --runInBand and the default runner, jest-circus peaks at >1200M before it goes OOM.

@thymikee
Copy link
Collaborator

thymikee commented Oct 1, 2019

The circus memory issue is tracked here: #8816.
cc @scotthovestadt

@SimenB
Copy link
Member

SimenB commented Mar 3, 2022

If this is still an issue using the latest version of Jest (27 at the time of writing), please provide a reproduction we can pull down and test. The leak mentioned above has been fixed 🙂

@SimenB SimenB closed this as completed Mar 3, 2022
@github-actions
Copy link

github-actions bot commented Apr 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants