gpt4 book ai didi

javascript - Node JS 可能检测到 EventEmitter 内存泄漏

转载 作者:行者123 更新时间:2023-11-30 18:17:05 25 4
gpt4 key购买 nike

<分区>

我已阅读 this question 中的答案并尝试了多种方法来解决我的问题但无法解决 - 因此从我这边发布此查询。

基本上,我有一个数组中的服务列表——大约有 1500 个服务在运行我的 NodeJS 应用程序的不同盒子上运行。根据我的代码,我通过 ssh 到/a 框并通过 expect 脚本,然后 cd 到特定目录以获取每个服务版本/构建 ID,这些服务版本/构建 ID 存储在每个特定路径的特定文件中服务。对于某些服务,相同的文件(具有版本/构建信息)有可能存储在框中的不同位置。所以我在应用程序中有算法,以防万一尝试获取第一条路径的详细信息失败,我将使用其他脚本来查找不同路径的信息:

主要代码块:

exports.getservicedetails = function(box,res) {
var job = [];
for (i = 0; i < services.length; i++ )
{
var children = new Object();
children.server = services[i];
children.box = box;
children.process = spawn('./scripts/info.sh', [children.server , children.box , getStageURL(children.box)]);
children.runstate = 1;
job.push(children);
createChildEvents(job, i, res);
}
}

现在我为每个生成的任务设置所有事件:

function createChildEvents(child, id, res){
(child[id]).process.stderr.on('data', function (data) {
(child[id]).runstate = 0;
});
(child[i]).process.on('exit', function (code) {
(child[id]).runstate = 0;
checkstate(child, res); // function to check if all spawned tasks has exited
});
(child[id]).process.stdout.on('data', function (data) {
var result = data.toString().split("\r\n"); // split the stdout outputted lines
for (var i = 0; i < result.length; i++)
{
console.log('Server : ' + (child[id]).server + " PID : " + (child[id]).process.pid + ' ' + (child[id]).box);
if ((child[id]).box.length > 0 && result[i].match(/No such file or directory/gi) != null) {
(child[id]).process = spawn('./scripts/info2.sh ',[(child[id]).server, (child[id]).box, getStageURL((child[id]).box)]);
(child[id]).box = '';
(child[id]).runstate = 1;
createChildEvents(child, id, res);
break;
}
if(result[i].match(/release_version*/) != null || result[i].match(/app.version*/) != null)
(child[id]).serversion = (result[i].split('='))[1];
if(result[i].match(/release_number*/) != null || result[i].match(/app.id*/) != null)
(child[id]).serproduct = (result[i].split('='))[1];
}
});
}

问题是在获得如下所述的第 11 个控制台日志后,我看到错误:

Server : a PID : 27200 myboxname
Server : b PID : 31650 myboxname
Server : d PID : 31644 myboxname
Server : e PID : 31664 myboxname
Server : f PID : 28946 myboxname
Server : g PID : 32507 myboxname
Server : h PID : 29329 myboxname
Server : i PID : 29905 myboxname
Server : j PID : 29883 myboxname
Server : k PID : 481 myboxname
Server : l PID : 777 myboxname
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:168:15)
at EventEmitter.once (events.js:189:8)
at Transport.logException (src/node_modules/winston/lib/winston/transports/transport.js:118:8)
at logAndWait (src/node_modules/winston/lib/winston/logger.js:613:15)
at async.forEach (src/node_modules/winston/node_modules/async/lib/async.js:86:13)
at Array.forEach (native)
at _forEach (src/node_modules/winston/node_modules/async/lib/async.js:26:24)
at Object.async.forEach (src/node_modules/winston/node_modules/async/lib/async.js:85:9)
at Logger._uncaughtException (src/node_modules/winston/lib/winston/logger.js:636:9)
at process.EventEmitter.emit (events.js:115:20)
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:168:15)
at EventEmitter.once (events.js:189:8)
at Transport.logException (src/node_modules/winston/lib/winston/transports/transport.js:117:8)
at logAndWait (src/node_modules/winston/lib/winston/logger.js:613:15)
at async.forEach (src/node_modules/winston/node_modules/async/lib/async.js:86:13)
at Array.forEach (native)
at _forEach (src/node_modules/winston/node_modules/async/lib/async.js:26:24)
at Object.async.forEach (src/node_modules/winston/node_modules/async/lib/async.js:85:9)
at Logger._uncaughtException (src/node_modules/winston/lib/winston/logger.js:636:9)
at process.EventEmitter.emit (events.js:115:20)

我尝试添加“process.setMaxListeners(0);”在我的代码中的很多地方,但我仍然看到这个错误?

知道如何解决这个问题吗?提前致谢。

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