Possible memory leak in nodejs interception
See original GitHub issueDescribe the bug
A clear and concise description of what the bug is.
I have a simple repo with 16 test files where every test file does the same thing of firing a simple fetch call and asserting for the response from the MSW handler. But when we run all the test files one after the other the heap usage keeps increasing. But when I comment the MSW server instantiation and other MSW related code heap memory stays constant.
Environment
msw: 0.28.2
nodejs: v12.14.0
npm: 6.13.4
Please also provide your browser version.
To Reproduce
Steps to reproduce the behavior:
- Clone the repo
https://github.com/mathanpec/msw-memory-leak-test
- Do
yarn install
- Execute
node --expose-gc ./node_modules/.bin/jest --silent --runInBand --detectOpenHandles --logHeapUsage
- I am specifically doing
node --expose-gc
and running GC in the AfterAll step to make sure there are no unused memory is left between test files.
Expected behavior
Memory heap should be consistent between every file runs or there should be a very minimal change. Check the following screenshot from the same repo without MSW server initialisation and handlers
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to Find, Fix, and Prevent Node.js Memory Leaks
Memory management for any application is essential. This post looks at what memory leaks are and how to avoid them in Node.js applications....
Read more >Debugging Memory Leaks in Node.js Applications - Toptal
Memory leaks in long running Node.js applications are like ticking time bombs that, if left unchecked in production environments, can result in devastating ......
Read more >The Misconception About React Memory Leak! - Dev Genius
I wrote this article to help clarify the misconception about memory leaks within React. There are many articles about how to avoid memory ......
Read more >Node.js Memory Leak Detection: How to Debug & Avoid Them
Learn what Node.js memory leaks are. Discover common causes and go through the whole debugging process, from detection to fixing and ...
Read more >Memory error checking in C and C++: Comparing Sanitizers ...
MSAN: Uninitialized memory reads; ASAN: Stack use after return; UBSAN: Undefined behavior; LSAN: Memory leaks; LSAN: Memory leaks with specific ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @kettanaito,
So I tried profiling the runs and this is what I could find,
You can see
ClientRequestOverride
is being referenced recursively and when I looked at the code,http.ClientRequest
is being monkey patched here but its not being set back to the original reference anywhere. This could be one possible cause but I am not very sure though.Hey, @mathanpec. I’ve commented on the pull request. Will have to check it out and get back to you. Thank you for your work on this, it looks great!