(node) warning: possible EventEmitter memory leak detected. 11 connected listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at DataSource.addListener (events.js:239:17)
at DataSource.once (events.js:265:8)
at DataSource.ready (/data/loopback-angular-admin/loopback-angular-admin/node_modules/loopback-datasource-juggler/lib/datasource.js:2038:8)
https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/datasource.js
contains a
var EventEmitter = require('events').EventEmitter;
I failed to increase maxlisteners, and avoid warning, in the code.
@raymondfeng What do you need to help me close the issue?
The issue _may_ be in loopback-datasource-juggler.
Current problem for me is to find the quickest easiest patch.
maxlisteners(10) was made for a reason maxlisteners(0) is probably not good.
https://nodejs.org/docs/latest/api/events.html#events_emitter_getmaxlisteners
x-ref loopback issues:
open https://github.com/strongloop/loopback/issues/1186
closed https://github.com/strongloop/loopback/issues/404
downstream issue: https://github.com/beeman/loopback-angular-admin/issues/150
I have the same problem. The code which triggers the warning:
module.exports = (app, cb) => {
app.dataSources.db.autoupdate(err => {
if (err) throw err;
cb();
});
};
How do I fix that? process.setMaxListeners(0) doesn't help.
Would one of you guys like to submit a patch? I think it's as simple as using setMaxListenerss as recommended, but somewhere in Juggler's code. I do not have time to look into this ATM, but I could do a code review/merge if you guys send a PR.
Also, which connectors are you guys using? Is the same error happening in multiple connectors or just in-memory?
@superkhau for me this happens with PostgreSQL connector but not with memory connector.
This change fixes the warning for me: https://github.com/strongloop/loopback-connector/compare/master...sochka:patch-1 Although as I see now, my warning is slightly different, maybe there are two places where the fix is needed. My warning was in loopback-connector package:
(node) warning: possible EventEmitter memory leak detected. 11 connected listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at DataSource.addListener (events.js:239:17)
at DataSource.once (events.js:265:8)
at PostgreSQL.SQLConnector.execute (E:\Projects\shopimate-api\node_modules\loopback-connector\lib\sql.js:397:28)
at PostgreSQL.getTableStatus (E:\Projects\shopimate-api\node_modules\loopback-connector-postgresql\lib\migration.js:44:10)
at E:\Projects\shopimate-api\node_modules\loopback-connector-postgresql\lib\migration.js:93:12
at E:\Projects\shopimate-api\node_modules\async\lib\async.js:122:13
at _each (E:\Projects\shopimate-api\node_modules\async\lib\async.js:46:13)
at Object.async.each (E:\Projects\shopimate-api\node_modules\async\lib\async.js:121:9)
at PostgreSQL.autoupdate (E:\Projects\shopimate-api\node_modules\loopback-connector-postgresql\lib\migration.js:87:11)
at DataSource.autoupdate (E:\Projects\shopimate-api\node_modules\loopback-datasource-juggler\lib\datasource.js:870:18)
Can you provide a link to a test project with steps to reproduce the issue? See https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report.
@sochka Nice find, it's probably somewhere else too as you've stated.
Sorry, I don't have time to setup everything, but since I had this error from the very first day, this should reproduce it: generate at least one, any additional model beyond the default ones. Plus create a boot script with this contents:
module.exports = (app, cb) => {
app.dataSources.db.autoupdate(err => {
if (err) throw err;
console.log('Models autoupdated');
cb();
});
};
Replace default db datasource with PostgreSQL database.
Just updated the error message here https://github.com/strongloop/loopback-datasource-juggler/issues/805#issuecomment-172656819, copy-pasted the text from the wrong place at first.
I am having the same issue, since Nov 12, 2015. I describe it here https://github.com/strongloop/loopback/issues/1186#issuecomment-155959249 which code causing the error (If I run it with more then 11 data fixture files). Should I make a repository to demonstrate it?
I use postgres connector.
I cannot reproduce the error with mysql.
@sochka
I can reproduce with postgres connector. I do not get any errors when I add this line only.
this.dataSource.setMaxListeners(0);
let me if this works for all of you, and I will update the code. Thanks.
joining this issue from https://github.com/strongloop/loopback/issues/1186 (along with @loay). wondering if there is a fix like @loay's being considered. i didn't try that fix, but got past the problem in that linked issue by doing:
var ds = [my current ds];
if(ds.connected) {
ds.automigrate(...);
} else {
ds.once('connected', function() {
ds.automigrate(...);
});
}
... that is code i placed within my project. however, it'd be preferable to remove that in favor of a lower level fix in the SQLConnector module (as @loay suggests). thanks for all the tips in this issue, too!
I'm getting this error also with the PostgreSQL connector.
I am as well with PostgreSQL connector
Me as well
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
```
(node) warning: possible EventEmitter memory leak detected. 11 connected listeners added. Use emitter.setMaxListeners() to increase limit.
YOU HAVE TO PUT FOR EXAMPLE IF YOU HAVE MORE THAN 11 client.on put client.setMaxListeners(0) .
Adding EventEmitter.defaultMaxListeners = <MaxNumberOfClients> to node_modules\loopback-datasource-juggler\lib\datasource.js fixed may problem :)
Most helpful comment
joining this issue from https://github.com/strongloop/loopback/issues/1186 (along with @loay). wondering if there is a fix like @loay's being considered. i didn't try that fix, but got past the problem in that linked issue by doing:
... that is code i placed within my project. however, it'd be preferable to remove that in favor of a lower level fix in the
SQLConnectormodule (as @loay suggests). thanks for all the tips in this issue, too!