如何调试引发此错误的应用程序:
(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
进行原型设计。
使用该解决方案,我可以获得这个新的跟踪:
(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)