-
Notifications
You must be signed in to change notification settings - Fork 29
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
Memory leak each time cachableLookup is imported and constructed. #25
Comments
Well, we can see this way pretty easily: const CL = require('cacheable-lookup');
Array.from({ length: 1000 }).forEach(() => new CL())
|
While it's probably not normal to create 1000 |
I don't know if this is the only reason for the memory leak, but it seemed like a good place to start. https://github.com/szmarczak/cacheable-lookup/blob/master/source/hosts-resolver.js#L26-L49 Class constructors must be synchronous. I wish that wasn't the case, but that's just how classes have to work. 😓 In the code above, it looks like we're trying to hack around that, but it's not a good idea. There's a hidden requirement that This is clever when we know |
Separately, it may not be wise to use I don't see any code to stop watching or disable watching, but i could be wrong. Perhaps watching the hostfile should be opt-in? hostfiles don't change often, especially in a production server, and polling a file that never changes doesn't feel like a great use of the eventloop in a production environment. |
Thanks for the very detailed report, I will fix this issue ASAP. As a workaround you can disable the hosts file via setting |
Should definitely be opt-in. |
The hosts resolver is an internal module. It's not exposed to the public. To disable it you can do
I'd go even further. Only one |
Hi!
I think I've stumbled into a memory leak in cacheable lookup. This leak is present in got, as well as other libraries that are using
got
, such as webdriver.io.I'm working on a standalone example to help reproduce the problem.
The text was updated successfully, but these errors were encountered: