-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
How to clear used memory between test suites? (possible memory leak) #776
Comments
please update to a newer version and test again, currently latest version is 8.13.0, migrations guides also if you still have the issue after the upgrade, please make a reproduction repository so that it can be tested |
Thanks for the quick response. I updated and still got the same problem. But I discovered that when I create a project with the template I used, it presents the same problem, only on a much smaller scale because it has far fewer tests than my project (The "template" is actually a yeoman generator called rest). I made a repository with it in its initial settings to make it easier to test. The default version it uses of your library is the outdated one, but I made a branch called With that, it could be that the error is in some configuration of this template, so I will make an issue there as well. But I would be very grateful if you could give this repository a test to see what is happening (I don't think I have enough knowledge) |
i did some inspecting myself
at least the onces shown in your screenshot are expected to be there, because they are (module)global buffers (i dont know why they make it (module)global though), see https://github.com/mongodb/js-bson/blob/1dcca92b24e609a069ca7f4187e5b9521380b2f5/src/bson.ts#L68 i found that when disabling the following aside from those, i am not proficient in debugging these issues and i cannot figure out where the problem is, the only common things across runs i have found is that jest sometimes just does not clean-up the test-suite and somehow still references it (and so has duplicate modules in string and compiled form) note: i have never understood how to properly use the chrome memory debugger or how to read its output, not being much different in this case |
i still dont understand how to read the output of the chrome debugger fully, but my assumption for now is that jest somehow keeps all the test contexts around (for as long as jest is running), which includes all module definitions (by extension for now i have created this stackoverflow question in hopes someone more experienced has a better answer |
Thank you very much for your time and dedication in responding. I stayed last night debugging, and I also couldn't solve the problem. I found some questions and problems related to the 3.x version of the I also ran into mongoose-related issues (mostly on old versions), like this Automattic/mongoose#2874. But I tried the solutions mentioned there without success. On my
Yes, I got this feeling too. I was thinking of testing with another test lib just to see what the result would be I think you can close this issue if you want, if I have any updates I'll post it here in case it helps someone else. thank you so much again for your time and for asking the question on stack overflow |
i had been able to repro this issue without much else dependencies, see https://github.com/hasezoey/jest-mem-leak/tree/advanced
in the chain there is likely something like and most BSON related thing (at least those i found) were related to the module buffer of BSON which i mentioned earlier as i outlined in my last comments (and on stackoverflow), it seems the |
Yes, I saw this. I tested this repo with mocha just to see what the result would be in
Yes, this image shows the debugger attached to your test repo: There seem to be known issues regarding this behavior of jest like here jestjs/jest#7874 that jest leaks memory without any additional dependencies and here jestjs/jest#14042 several people mentioning a problem similar to the one I had at the beginning of this thread. Some people in these issues said they solved it by downgrading the node version to version 16.10, but I did that and tested it in your repo and still got the same memory leak. |
for now i have replaced the also see #579 (comment) @racs4 could you re-test with the current
Notes:
Edit: |
it seems to have worked, it's much better than it was before, even when inconsistent. I did some tests and got these interesting results:
Remembering that the repository where I tested has 390+ test suites and almost all of them use the |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
i know that is a jest problem, but if it can help someone i have mitigated this with 2 steps (reduce mem from 1.4gb to 650/700 mb)
this not resolve the problem but mitigate it. EDIT: |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
beta 9.0.0-beta.1 has been released, which has the replacement for |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
this was kinda wrongly marked stale, i will re-open this at least until 9.0.0 is properly released |
🎉 This issue has been resolved in version 9.0.0 🎉 The release is available on:
Manual message because semantic-release hit the limit i will close this now, because i cant reproduce more memory-leaks, please open a new issue (maybe reference this old one) if another problem occurs with the latest version |
Versions
package: mongo-memory-server
What is your question?
Hello, I'm using jest to perform integration tests and I have a lot of suites that were running smoothly. But as the number of suites increased, a considerable increase in memory usage was noticed, to the point that it is impossible to run the tests. (The image below shows the heap usage after some time testing)
Doing a bit of debugging, using
node --inspect-brk --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage
and taking a snapshot of the heap with the chromium inspection tool, you can see that there are several "lost" BSON objects in memory, which for some reason are referenced when moving from one test suite to another.My jest configuration follows a single file setup present in this template:
I already saw the recommended settings for jest present in the documentation of this library, but there a single instance of mongo-memory-server is created for all suites, while in the code of this template a new one is created for each test suite and I would like to keep it that way.
My question is if you or someone who has had this problem could help me to find out why these objects are getting referenced between one test suite and another, preventing them from being cleared from memory, and how to solve it.
Thanks in advance for any help
The text was updated successfully, but these errors were encountered: