change .on to .once, remove possible memory leaks #2420

Merged
merged 1 commit into from Oct 17, 2016

Conversation

Projects
None yet
2 participants
@duereg
Contributor

duereg commented Oct 14, 2016

In doing stress testing on my application, started seeing these messages in my logs:

(node) warning: possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at IncomingMessage.addListener (events.js:239:17)
    at IncomingMessage.Readable.on (_stream_readable.js:680:33)
    at Request.onRequestResponse (...node_modules/request/request.js:896:14)
    at emitOne (events.js:82:20)
    at ClientRequest.emit (events.js:169:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:433:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)
    at Socket.socketOnData (_http_client.js:322:20)
(node) warning: possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at IncomingMessage.addListener (events.js:239:17)
    at IncomingMessage.Readable.on (_stream_readable.js:680:33)
    at Request.onRequestResponse (.../node_modules/request/request.js:968:21)
    at emitOne (events.js:82:20)
    at ClientRequest.emit (events.js:169:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:433:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23)
    at Socket.socketOnData (_http_client.js:322:20)
    at emitOne (events.js:77:13)
@mikeal

This comment has been minimized.

Show comment
Hide comment
@mikeal

mikeal Oct 17, 2016

Member

Why is this function being called multiple times on the same request instance?

I'm +1 on using .once() whenever possible, so I'm +1 on this PR, but I am worried that there's another bug here that is calling this more times than it should.

Member

mikeal commented Oct 17, 2016

Why is this function being called multiple times on the same request instance?

I'm +1 on using .once() whenever possible, so I'm +1 on this PR, but I am worried that there's another bug here that is calling this more times than it should.

@duereg

This comment has been minimized.

Show comment
Hide comment
@duereg

duereg Oct 17, 2016

Contributor

@mikeal What you're saying makes sense... but I don't know the overall codebase for this well enough to diagnose. Sorry I can't be more helpful here.

Contributor

duereg commented Oct 17, 2016

@mikeal What you're saying makes sense... but I don't know the overall codebase for this well enough to diagnose. Sorry I can't be more helpful here.

@mikeal mikeal merged commit cb8c1f6 into request:master Oct 17, 2016

3 checks passed

codecov/patch 100% of diff hit (target 91.55%)
Details
codecov/project 91.55% (+0.00%) compared to 90cf8c7
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment