question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible memory leak in nodejs interception

See original GitHub issue

Describe 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.

Screenshot 2021-04-26 at 7 23 24 PM

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:

  1. Clone the repo https://github.com/mathanpec/msw-memory-leak-test
  2. Do yarn install
  3. Execute node --expose-gc ./node_modules/.bin/jest --silent --runInBand --detectOpenHandles --logHeapUsage
  4. 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

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mathanpeccommented, Apr 26, 2021

Hi @kettanaito,

So I tried profiling the runs and this is what I could find,

image

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.

1reaction
kettanaitocommented, Apr 30, 2021

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found