supertest icon indicating copy to clipboard operation
supertest copied to clipboard

warning: possible EventEmitter memory leak detected. When user supertest.agent(require(server.js))

Open dh376 opened this issue 10 years ago • 9 comments

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.

dh376 avatar Jan 23 '16 19:01 dh376

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.

neochrome avatar Mar 29 '16 10:03 neochrome

+1

dimitrisfasoulas avatar Jul 04 '16 14:07 dimitrisfasoulas

+1

jbroughton72 avatar Sep 20 '16 16:09 jbroughton72

+1

geoffcorey avatar Dec 13 '16 16:12 geoffcorey

+1

dmitrovskiy avatar Apr 05 '17 07:04 dmitrovskiy

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.

tatianacmh avatar Apr 30 '17 20:04 tatianacmh

+1 ping @Remy-Luciani

fredericbarthelet avatar May 19 '17 14:05 fredericbarthelet

+1

Remy-Luciani avatar May 19 '17 16:05 Remy-Luciani

+1

luck-arancibia avatar Apr 02 '19 13:04 luck-arancibia