javascript - 如何对来自 Node 的 MaxListenersExceededWarning 消息进行故障排除?
问题描述
我正在通过 mocha(通过 Node)运行 Selenium 测试,每次运行全部测试时,我都会在同一个确切位置看到此警告消息:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added. Use emitter.setMaxListeners() to increase limit
如果我运行一个测试,我看不到这个问题,所以这个问题似乎与运行多个测试有关。
我试过指定--trace-warnings
命令行参数,但它似乎没有做任何事情。具体来说,我修改了我的测试运行脚本来做到这一点:
node --trace-warnings node_modules/mocha/bin/mocha ...
我仍然看到相同的警告消息,但我没有看到堆栈跟踪。
SO 上的其他帖子提供了关于增加限制的建议,但这不是我想要在这里做的。我试图弄清楚为什么首先出现此警告。
解决方案
我不知道为什么命令行参数不起作用,但我找到了一种从这里获取堆栈跟踪的替代方法:
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
});
推荐阅读
- jakarta-ee - 如何访问 weblogic 集群中 adminserver 的 JNDI 树?
- webtask - 如何在 webtask 中使用 res.redirect?
- php - 使用带有数字索引的 php 提取函数
- mysql - Docker phpmyadmin 显示 db_name 但不显示 db 表
- css - FlexBox:我怎样才能让盒子固定在另一个下面
- vba - PR_SPAM_TRUSTED_SENDERS_W 和 PR_SPAM_BLOCKED_SENDERS
- python - Pandas DataFrame check if column value exists in a group of columns
- r - 如何在 R 中将 .csv 文件转换为 .tab?
- django - 如何使用 Django 频道和服务器 daphne 配置主管
- java - 在文件中搜索字符或字符串(java)