-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fix memory leak #137
Fix memory leak #137
Conversation
this is cool, but i have a noobish question. how do you test or "measure" the memory-leak-fix? do you have a script to simulate typical usage and compare the expected memory usage vs actual? |
Hi @tmax - great question! If you look in Normally, node caches modules once they are First, we look at the memory usage with Then we require "fresh" the module 4000 times, simulating 4000 unit tests. We then call Before this fix, garbage collecting had no effect because every copy of the module was still referenced by Finally, we look at the memory usage with |
Thanks! Landed on [email protected]. |
@@ -1,6 +1,8 @@ | |||
var fs = require('fs') | |||
var polyfills = require('./polyfills.js') | |||
var legacy = require('./legacy-streams.js') | |||
var clone = require('./clone.js') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing clone.js
great work! |
Thank you! |
@dylang This doesn’t seem to resolve the issue completely on Node 11 … do you think you could take a look? We generally run graceful-fs’s tests as part of each Node.js release, so having them pass is really nice for us :) |
ping @dylang ? |
This works fine on version 4.1.15 for fixing the memory leak, but when I upgrade to version 4.2.3 the memory leak comes back. Was a regression introduced with the changes in 4.2.x? |
I'm experiencing the same as @addaleax. I have this package locked at v4.1.15 but it's still causing memory leaks in node v11, v12, v13 |
Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔌
graceful-fs
is relied on by many major projects. Test frameworks, such asjest
, both reset the module cache between tests to facilitate mocking, and rely ongraceful-fs
.Because of this,
graceful-fs
is re-wrappingfs
multiple times, causing ever-growing memory leaks. In a project with a a few thousand tests, this balloons to GB.Three memory leaks were fixed in this PRz
fs.close
was getting re-wrapped every timegraceful-fs
was loaded.fs.closeSync
was getting re-wrapped every timegraceful-fs
was loaded.fs
generated by./fs.js
was getting re-wrapped every timegraceful-fs
was loaded.These memory leaks show up when:
graceful-fs
is required.Note:
--enable-gc
was added to the test runner so that we can monitor memory usage in one of the tests.Fixes #102
Some related tickets: