gpt4 book ai didi

node.js - winston -MaxListenersExceededWarning : Possible EventEmitter memory leak detected

转载 作者:太空宇宙 更新时间:2023-11-03 22:04:20 27 4
gpt4 key购买 nike

在使用winston-daily-rotate-file包进行文件日志记录时,在winston中出现以下错误,代码与winston控制台日志记录配合良好,

  MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at DailyRotateFile.addListener (events.js:272:10)
at DailyRotateFile.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:217:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)
(node:20805) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 finish listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at DailyRotateFile.addListener (events.js:272:10)
at DailyRotateFile.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:216:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)
(node:20805) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 error listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:256:17)
at Console.addListener (events.js:272:10)
at Console.once (events.js:301:8)
at asyncForEach (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:217:17)
at /home/ubuntumachine/Desktop/project/node_modules/async/internal/withoutIndex.js:9:16
at eachOfArrayLike (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:65:9)
at exports.default (/home/ubuntumachine/Desktop/project/node_modules/async/eachOf.js:9:5)
at eachLimit (/home/ubuntumachine/Desktop/project/node_modules/async/forEach.js:80:24)
at ExceptionHandler._uncaughtException (/home/ubuntumachine/Desktop/project/node_modules/winston/lib/winston/exception-handler.js:203:5)
at process.emit (events.js:198:13)

尝试将最大监听器设置为无穷大,

const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.setMaxListeners(Infinity);

仍然面临同样的问题。

最佳答案

我遇到了一个相关的案例,标题中提到了警告,所以只是与可能参与此主题的其他人分享我的调查见解:

  • 弹出此警告的原因是什么?嗯,this comment in this relevant thread解释得很好。简而言之:广泛使用交通工具。
  • 如何禁用警告?我发现很少有地方(例如 this one )提供更新最大监听器。他们使用 process.setMaxListeners(0);,这与问题中使用的不同。
  • 应该禁用该警告吗?我倾向于不禁用(如 first comment in this thread 中所述)。
  • 为什么clear()有帮助?好吧,我没有读太多相关内容,但根据documnation - 它删除所有传输。
  • 在其他什么情况下可能会发生此错误? - 当使用传输创建大量记录器实例时。我就是这样。

关于node.js - winston -MaxListenersExceededWarning : Possible EventEmitter memory leak detected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58653678/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com