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
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [Keyv]. Use emitter.setMaxListeners() to increase limit #1523
Comments
Actually this isn't a memory leak. But the code can be optimized anyway. |
@szmarczak ah, so the listener is removed after handling is complete so this only occurs when you have more than 10 requests in flight at any one time? |
Correct. |
@szmarczak so how would you suggest proceeding because having many requests in flight at any one time is fairly normal use-case. Does the max listeners limit need raising? Warnings being emitted during normal operation scares the villagers, such as myself. |
The workaround lies in the very title of the issue:
Simply pass a |
@szmarczak I expected that too, but it doesn't. That's why I created this (by the way, thanks for helping chase this around). const got = require('got');
const Keyv = require('keyv');
const keyv = new Keyv();
keyv.setMaxListeners(10000);
const client = got.extend({
cache: {
get: (key) => {
return undefined;
},
set: (key, value) => {
}
}
});
const keyvClient = got.extend({
cache: keyv
});
(async () => {
console.log('Simple cache client', 'start');
let promises = [];
for (let i = 0; i < 20; i++) {
promises.push(client(`https://www.google.com?${i}`, { method: 'HEAD' }));
};
await Promise.all(promises);
console.log('Simple cache client', 'end');
console.log('Keyv cache client', 'start');
promises = [];
for (let i = 0; i < 20; i++) {
promises.push(keyvClient(`https://www.google.com?${i}`, { method: 'HEAD' }));
};
await Promise.all(promises);
console.log('Keyv cache client', 'end');
console.log('Done');
})(); Output
|
It's because it creates another Keyv instance: So I don't think there is any workaround at all for now :( |
@szmarczak ok. Many thanks for the help with all of this! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm facing issues for similar reasons, it's also registering a once error listener that gets cleared after response, which is okay-ish but it doesn't account for databases connection error (eg: replicas failover) which crashes the process and prevent network fallback. I think Got could also benefit from this, I've opened a PR about this at |
Looks good. I'll look deeper this week to look out for bugs if any.
Yes. I'm going to rewrite |
@szmarczak we've been having some issues with timeouts of tests lately and we're wondering if this is now potentially part of the cause. Have you made any progress on figuring out a fix for this? |
This has nothing to do with timeouts. |
Any update on it ? |
@Fab-z4qx - I believe this has been updated in |
@sindresorhus or @szmarczak - this I believe has been resolved and you can close it as the pull request was merged here: jaredwray/cacheable#101 |
@sindresorhus - did you want to close this? |
Describe the bug
When using simple cache adapters MaxListenersExceededWarning is emitted. This has previously been investigated in #792 and #1128 but either it is a regression or did not account for highly asynchronous environments with 100's of parallel requests.
Unsure if this is best opened in either keyv or cacheable-request, but given it was declared solved in #1128 I've opened it here first.
Actual behavior
Code to reproduce
Checklist
Related Tickets
jaredwray/cacheable#97
The text was updated successfully, but these errors were encountered: