简体   繁体   中英

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:

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. 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. 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

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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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