简体   繁体   English

如何解决来自Node的MaxListenersExceededWarning消息?

[英]How do I troubleshoot MaxListenersExceededWarning messages from Node?

I'm running Selenium tests through mocha (through Node) and I see this warning message at the same exact spot every time I run my full battery of tests: 我正在通过Mocha(通过Node)运行Selenium测试,每次我进行全部测试时,都会在同一确切位置看到此警告消息:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit

I don't see this problem if I run a single test, so the issue seems to be related to running multiple tests. 没有看到这个问题,如果我运行一个测试,所以这个问题似乎与运行多个测试。

I've tried specifying the --trace-warnings command-line argument, but it doesn't seem to do anything. 我尝试指定--trace-warnings命令行参数,但是它似乎没有任何作用。 Specifically, I modified my test runner script to do this: 具体来说,我修改了我的测试运行器脚本来做到这一点:

node --trace-warnings node_modules/mocha/bin/mocha ...

I still see the same warning message, but I don't see a stack trace. 我仍然看到相同的警告消息,但是没有看到堆栈跟踪。

Other posts on SO offer suggestions on increasing the limit, but that's not what I'm looking to do here. SO上的其他帖子提供了增加限制的建议,但这不是我要在此处执行的操作。 I'm trying to figure out why this warning is appearing in the first place. 我试图弄清楚为什么此警告首先出现。

I don't know why the command-line argument didn't work, but I found an alternative approach to get the stack trace from here: 我不知道为什么命令行参数不起作用,但是我找到了另一种方法来从此处获取堆栈跟踪:

https://nodejs.org/docs/latest/api/process.html#process_event_warning https://nodejs.org/docs/latest/api/process.html#process_event_warning

process.on('warning', (warning) => {
  console.warn(warning.name);    // Print the warning name
  console.warn(warning.message); // Print the warning message
  console.warn(warning.stack);   // Print the stack trace
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM