firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Unit test memory leak

Open vojdan opened this issue 2 years ago • 2 comments

[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 avatar Aug 08 '22 03:08 vojdan

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.

google-oss-bot avatar Aug 08 '22 03:08 google-oss-bot

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

joehan avatar Aug 08 '22 20:08 joehan

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: https://github.com/facebook/jest/issues/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.

christhompsongoogle avatar Dec 30 '22 00:12 christhompsongoogle