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

Node 16 Memory leak #23

Open
odeadglaz opened this issue Feb 24, 2022 · 6 comments
Open

Node 16 Memory leak #23

odeadglaz opened this issue Feb 24, 2022 · 6 comments

Comments

@odeadglaz
Copy link

odeadglaz commented Feb 24, 2022

We are currently using (and loving) this package over our current production applications while we using Node14.

As part of our tech upgrades, we are moving towards Node16 and while we tested our codebase with the new node version, we discovered while monitoring to pods that we huge memo leak.

I tried reproducing the issue using the heapdump script of this package and I got this following results:

-- Node 14 --

  • require

image

  • importFresh

image

-- Node 16 --

  • require

image

  • importFresh

image

It seems that there is a notable difference between two, I might have missed something tho has anybody else had experienced that?

Appreciated, cheers 🎉

@sindresorhus
Copy link
Owner

Since the memory leak occurs after upgrading Node.js, it's most likely a Node.js bug.

@sindresorhus
Copy link
Owner

Would you be able to try this branch and see if it improves the situation? https://github.com/sindresorhus/import-fresh/tree/memory-leak

@odeadglaz
Copy link
Author

odeadglaz commented Feb 25, 2022

Since the memory leak occurs after upgrading Node.js, it's most likely a Node.js bug.

Yea it could very be, I wasn't able to determine it.

Would you be able to try this branch and see if it improves the situation? https://github.com/sindresorhus/import-fresh/tree/memory-leak

Sure, I'll give it a shot and would update, thanks for the fast response 🙏

@odeadglaz
Copy link
Author

So i gave it a shot, I got same results sadly, While inspecting the memory profiler I can see that the modules are kept in memory and not garbage collected due to some reference pointing them which I didn't quite understand, altho the require.cache seems clean (as it should) from any reference to that module being freshly imported.

This acts completely different in Node 14, where the module is being properly garbage collected and it only keeps 1 reference.

@odeadglaz
Copy link
Author

odeadglaz commented Feb 25, 2022

So I've done a bit more tracing and it seems to be related to this commit.

For some reason, vm keeps reference to the deleted module via importModuleDynamically which causes the leak.

image

So it most definitely relates to node 👌

@odeadglaz
Copy link
Author

It seems it was already reported as Node issue, once it resolved I think it should work as expected once again

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

No branches or pull requests

2 participants