warning: possible EventEmitter memory leak detected. When user supertest.agent(require(server.js))
The Error Message
(node) warning: possible EventEmitter memory leak detected. 11 connection listeners added. Use emitter.setMaxListeners() to increase limit. Trace at Server.addListener (events.js:179:15) at Server._listen2 (/Users/DanHeoFAPL/Desktop/fapl-code/loopback/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:65:10) at listen (net.js:1182:10) at Server.listen (net.js:1267:5) at Test.serverAddress (/Users/DanHeoFAPL/Desktop/fapl-code/loopback/node_modules/supertest/lib/test.js:56:33) at new Test (/Users/DanHeoFAPL/Desktop/fapl-code/loopback/node_modules/supertest/lib/test.js:36:12) at TestAgent.(anonymous function) as post at /Users/DanHeoFAPL/Desktop/fapl-code/loopback/test/Dan/helpers/pictorials.js:136:9 at /Users/DanHeoFAPL/Desktop/fapl-code/loopback/node_modules/async/lib/async.js:181:20 at Object.async.forEachOf.async.eachOf (/Users/DanHeoFAPL/Desktop/fapl-code/loopback/node_modules/async/lib/async.js:233:13)
Cause
I'm testing Loopback APIs with mocha and supertest. To start the server, I do
server = require('../../server/server.js');
api = supertest.agent(server);
This is what causes the error. When I have the server listen to a port and use the port to make api calls, this does not cause the problem. Like this:
server = require('../../server/server.js');
app = server.start()
api = supertest('http://localhost:3000');
There are issues open in async-listner github: https://github.com/othiym23/async-listener/issues/29 But I only get this when using supertest.agent(server) as I mentioned previously... This always happens when I try to make multiple api calls with async.each.
I had a similar issue when setting up supertest from within the World-constructor in Cucumber.js. Basically what happend then was an initialization for every scenario across all features which lead to the message about EventEmitter leakage. My solution to the problem was to move the launching of the server and supertest setup to a pre-all-scenarios hook, which seemed to fix the problem.
+1
+1
+1
+1
I have the same problem, when using supertest or supertest as promised. I did what you did dh376, and indeed, the annoying warning doesn't appear.
+1 ping @Remy-Luciani
+1
+1