Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

node.js - NodeJS : How to debug "EventEmitter memory leak detected. 11 listeners added"

How can I debug my application which throw this error:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:653:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:527:26)

I could not find the assumed leaking object for increasing listener limit by .setMaxListeners(0);

SOLUTION (from fardjad and jan salawa)

With jan salawa's searches I found a working library (longjohn) for increasing stack traces verbose. With fardjad's response I have found that we have to prototype EventEmitter.addListener AND EventEmitter.on.

With the solution I could get this new trace:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at EventEmitter.addListener.EventEmitter.on (xxx/main.js:44:15)
    at Readable.on (_stream_readable.js:653:33)
    at ServerResponse.assignSocket (http.js:1072:10)
    at parser.onIncoming (http.js:1979:11)
    at parserOnHeadersComplete (http.js:119:23)
    at socket.ondata (http.js:1912:22)
    at TCP.onread (net.js:510:27)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It turns out that this is a bug in nodejs core, we are talking about this problem here : https://github.com/joyent/node/issues/5108

Solution for bugged http servers thats throw an EventEmitter memory leak detected and fill up the available memory / available CPU times :

Revert to legacy version v0.8.23. (You can download and install/compile it from here : http://blog.nodejs.org/2013/04/08/node-v0-8-23-legacy/)

UPDATE 2018 : I see several feedbacks on this topic whereas the problem looks to be gone since years. Note that this response is only for a leaking http server build with nodejs. If you are in other scenario, please look the others responses on this thread and dont downgrade your version (as suggested on this response), you will waste your time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...