问题描述
如何调试抛出此错误的应用程序:
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)
我找不到通过 .setMaxListeners(0);
解决方案(来自 fardjad 和 jan salawa)
通过 jan salawa 的搜索,我找到了一个工作库 (longjohn),用于增加详细的堆栈跟踪.通过 fardjad 的回应,我发现我们必须对 EventEmitter.addListener
AND EventEmitter.on
进行原型设计.
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)
推荐答案
原来这是nodejs core的一个bug,我们在这里讨论这个问题:https://github.com/joyent/node/issues/5108
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
问题的 http 服务器的解决方案,它会引发 EventEmitter 内存泄漏检测
并填满可用内存/可用 CPU 时间:
Solution for bugged http servers thats throw an EventEmitter memory leak detected
and fill up the available memory / available CPU times :
恢复到旧版本 v0.8.23
.(您可以从这里下载并安装/编译它:http://blog.nodejs.org/2013/04/08/node-v0-8-23-legacy/)
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/)
2018 年更新: 我看到一些关于这个主题的反馈,而这个问题似乎已经消失多年了.请注意,此响应仅适用于使用 nodejs 构建泄漏的 http 服务器.如果您处于其他情况,请查看此线程上的其他回复,不要降级您的版本(如该回复中建议的那样),您会浪费时间.
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.
这篇关于NodeJS:如何调试检测到的“EventEmitter 内存泄漏".添加了 11 个听众"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!