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

Unit test memory leak #4836

Closed
vojdan opened this issue Aug 8, 2022 · 3 comments
Closed

Unit test memory leak #4836

vojdan opened this issue Aug 8, 2022 · 3 comments
Assignees

Comments

@vojdan
Copy link

vojdan commented Aug 8, 2022

[REQUIRED] Environment info

firebase-tools: 11.4.2
node --version: v16.16.0

Platform: MacOS Monterey 12.5, MacBook Pro Apple M1 Max, 64 GB

[REQUIRED] Test case

Repro: https://github.com/vojdan/firebase-memory-leak

Look at Issue 2 in README.md
https://github.com/vojdan/firebase-memory-leak#issue-2---memory-leak

[REQUIRED] Steps to reproduce

GIF included in README

https://github.com/vojdan/firebase-memory-leak#issue-2---memory-leak

Start firebase emulators (in terminal 1)

npm run emulators:test

Run tests in watch mode (in terminal 2)

npm run test:memleak

[REQUIRED] Expected behavior

Heap memory will stay low. Note: memory stays low when running npm run test:watch

[REQUIRED] Actual behavior

Heap memory increases on every re-run and eventually crashes. Press Enter in terminal 2 after test run finishes to re-run.

@vojdan vojdan added the bug label Aug 8, 2022
@google-oss-bot
Copy link
Contributor

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

@joehan
Copy link
Contributor

joehan commented Aug 8, 2022

Thanks for reporting this with a clear repro! We will investigate.

@christhompsongoogle
Copy link
Contributor

christhompsongoogle commented Dec 30, 2022

On linux I get a consistent 56-166MB heap size when restarting node, nothing interesting.

When using the jest re-run command the heap allocation starts to climb. This seems like a problem with Jest and not with the emulators

I looked into this for some time - it seems that Jest has a serious memory leak problem and there's no easy solution, see this issue open since 2019:
jestjs/jest#7874

Some have suggested downgrading to Node 16.10 to mitigate the issue.

I'm not a Jest expert, but I spent some time following this heap dump debugging pathway:

https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html

I wasn't able to find a conclusive culprit - it may be within Jest. It LOOKS like the heap is filling up with strings (44MB and 62% heap allocation is in strings).

At any rate I don't think this is an issue we can/should solve within Firebase. Feel free to let me know if you disagree but I'm closing this one out for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants