这似乎是关于SO的一个常见问题,但我已经尝试了所有的建议,似乎无法超越它。常见的解决方案似乎是战略性的:
process.setMaxListeners(0);
但我似乎无法弄清楚把它放在哪里。它发生在我的测试用例中:https://github.com/socketwiz/swblog/blob/master/test/contact.js
一开始很好但是当我开始添加更多测试用例时,它开始产生以下错误:
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at process.EventEmitter.addListener (events.js:160:15)
at process.on.process.addListener (node.js:769:26)
at Object.module.exports [as shutdown] (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/middleware/shutdown.js:41:13)
at Object.proto._middleware (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/appcore.js:166:24)
at next (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/appcore.js:77:18)
at Object.configure (/Users/socketwiz/Sites/swblog/index.js:10:5)
at Object.proto._configure (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/appcore.js:85:28)
at Object.proto.init (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/appcore.js:35:14)
at create (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/lib/appcore.js:258:13)
at Promise.apply (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/node_modules/q/q.js:1122:26)
at Promise.promise.promiseDispatch (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/node_modules/q/q.js:752:41)
at /Users/socketwiz/Sites/swblog/node_modules/kraken-js/node_modules/q/q.js:1337:14
at flush (/Users/socketwiz/Sites/swblog/node_modules/kraken-js/node_modules/q/q.js:108:17)
at process._tickDomainCallback (node.js:459:13)
它似乎没有任何特定的测试,因为如果我评论一个失败的测试,它将转移到另一个测试。
为了解决这个问题,我尝试过设置:
server.setMaxListeners(0);
此处:https://github.com/socketwiz/swblog/blob/master/test/contact.js#L21
我也尝试过设置
server.setMaxListeners(0);
此处:https://github.com/socketwiz/swblog/blob/master/index.js#L15
但我似乎没有任何运气。我应该提出任何想法,还是有更好的解决方案?我正在使用节点v0.10.26。我的整个项目可以在这里找到参考:https://github.com/socketwiz/swblog
尽我所知,一切正常,这只是一个警告,但它有点烦人:(