我已经在this question中阅读了答案并尝试了很多方法来解决我的问题,但却没有 - 因此从我这边发布了这个问题。
基本上我有一个数组中的服务列表 - 在我的NodeJS应用程序运行的其他框上运行的数字大约为1500。根据我的代码,我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);'在我的代码中的许多点,但我仍然看到这个错误?
知道如何解决这个问题?提前谢谢。
答案 0 :(得分:2)
你有一个错字。 child[i]
代替child[id]
因此,您在每个createChildEvents
调用中为同一个发射器设置了一个侦听器。