msw icon indicating copy to clipboard operation
msw copied to clipboard

Memory leak while using node 16 (but not 14)

Open jyuvaraj03 opened this issue 4 years ago • 6 comments

Prerequisites

Environment check

  • [X] I'm using the latest msw version
  • [x] I'm using Node.js version 14 or higher

Node.js version

v16.14.2

Reproduction repository

https://github.com/mathanpec/msw-memory-leak-test

Reproduction steps

  1. Use node version 16.
  2. Clone the reproduction repo (originally created by @mathanpec for #710).
  3. Edit package.json to change msw package version to 0.39.2 and execute yarn install.
  4. Execute node --expose-gc ./node_modules/.bin/jest --silent --runInBand --logHeapUsage.
  5. Notice the heap usage increase for each test.

Current behavior

There seems to be some memory leak going on when using node 16.

Screenshot 2022-04-05 at 8 15 11 PM

The heap profile also seems to show multiple copies of the same msw index file. Screenshot 2022-04-05 at 9 07 52 PM

Expected behavior

Memory heap should not increase for each test file run when using node 16. Executing jest with node 14 does not cause any memory leak as shown in the following screenshot:

Screenshot 2022-04-05 at 8 14 27 PM

jyuvaraj03 avatar Apr 05 '22 15:04 jyuvaraj03

Hey, @jyuvaraj03. Thank you for reporting this one!

We will look into the reproduction repo and investigate what is causing the leak. I somewhat doubt it's related to Node 16 but rather to the latest version of MSW. But I can't rule out any options just yet.

If anybody has time to look into this, I'd appreciate the help. Otherwise, I'd get to it when I have time.

kettanaito avatar Apr 07 '22 12:04 kettanaito

so should we downgrade the msw version?

finalight avatar Apr 16 '22 14:04 finalight

@finalight, if you're experiencing this issue then yes, by all means, remediate it by downgrading. I'd much appreciate help with this one, it shouldn't take too much time to analyze the profiler's output and see where the memory heap/leak occurs.

kettanaito avatar Apr 17 '22 15:04 kettanaito

We also experience this issue, except we don't use msw. It also reproduces on Node 18.

artkoshelev avatar May 27 '22 09:05 artkoshelev

We also experience this issue, except we don't use msw. It also reproduces on Node 18.

ah i see, so the memory leak is because of the node, not the msw

finalight avatar May 27 '22 13:05 finalight

I searched around a little. It seems the memory leak is in jest itself (for node 16.11.0+) and not in msw. @kettanaito, feel free to close this issue if needed. Here's the bug report in the jest repo if anyone is interested.

jyuvaraj03 avatar May 27 '22 18:05 jyuvaraj03