Skip to content
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

When required in combination with supertest, causes eventemitter memory leak #29

Open
STRML opened this issue Feb 7, 2015 · 15 comments

Comments

@STRML
Copy link
Contributor

STRML commented Feb 7, 2015

Supertest creates and tears down an HTTP request listener per-test, so it's not uncommon to see something like:

(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 (~/api/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:64:10)
    at listen (net.js:1155:10)
    at Server.listen (net.js:1240:5)
    at Test.serverAddress (~/api/node_modules/loopback-testing/node_modules/supertest/lib/test.js:59:33)
    at new Test (~/api/node_modules/loopback-testing/node_modules/supertest/lib/test.js:38:12)
    at Object.obj.(anonymous function) [as post] (~/api/node_modules/loopback-testing/node_modules/supertest/index.js:25:14)
    at Context.<anonymous> (~/api/node_modules/loopback-testing/lib/helpers.js:243:46)
    at Hook.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:217:15)
    at next (/usr/local/lib/node_modules/mocha/lib/runner.js:258:10)
    at Immediate.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runner.js:275:5)
    at Immediate._onImmediate (~/api/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
    at processImmediate [as _immediateCallback] (timers.js:358:17)

Perhaps this should be tearing down on 'close'?

In any case, should this even be running in Node 0.12? I thought it was just a polyfill for something that was going to ship in core.

@hayes
Copy link
Collaborator

hayes commented Feb 7, 2015

Interesting, the one thing I notice is the on('connection') that gets added to _listen2 should probably be changed to a once. That would probably fix this issue, it might be better to just make sure the listener was not already added before doing on. But I can definitely see how shutting down and reconnecting a a server could cause this issue. Its a pretty strange pattern, so not too surprising no one has run into this before

@STRML
Copy link
Contributor Author

STRML commented Feb 8, 2015

Yeah it is a bit strange. I don't think you'd see it much in production though, just test, so not the highest of priorities but it is a bit annoying.

@STRML
Copy link
Contributor Author

STRML commented Feb 8, 2015

In any case should this code even be running in Node 0.12?

@hayes
Copy link
Collaborator

hayes commented Feb 10, 2015

it should be mostly functional, see #27 and #28

@zanemcca
Copy link

I have been having the same issue. It only happens if I use supertest(require('app')) but not when I connect to an already running app on a specified url using supertest('http://localhost:1234').

@nicolasgramlich
Copy link

Hey guys, is there any update on this issue? We're having a fairly big test suite and with this leak our tests just die in the middle of execution after a few thousand (≈ 4000) https calls through supertest(require('app').

@dh376
Copy link

dh376 commented Jan 22, 2016

I'm running into same issue here.
Only when I use
supertest(require('app'))
as well!

@DaGaMs
Copy link

DaGaMs commented May 1, 2016

Same here with a loopback app

@mitsos1os
Copy link

Same as @DaGaMs
running with loopback app produces memory leak...
Related: ladjs/supertest#307

@imjordanxd
Copy link

imjordanxd commented Feb 4, 2021

any updates? 👀 still an issue in 2021 👎

@pshaddel
Copy link

Any no update or workaround about this issue?

@Qard
Copy link
Collaborator

Qard commented Aug 27, 2022

This hasn't been maintained for years. Why are you still using it when the functionality has been in Node.js core for several years now? 🤔

@rochdev
Copy link

rochdev commented Aug 27, 2022

The feature in Node core mentioned above: https://nodejs.org/api/async_context.html.

@pshaddel
Copy link

@Qard I am using supertest, and there were some memory leaks, I was here because there was an open issue on superagent which was related to this one.

@Qard
Copy link
Collaborator

Qard commented Aug 27, 2022

Supertest doesn't use async-listener. Somewhere else in your dependency graph something is still using this module when it shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests