I've read answers in this question and tried many ways to resolve my issue but could not - hence posting this query from my side.
Basically I have a list of services in an array - which comes to ~ 1500 in numbers running on a different box other that where my NodeJS application is running. As per my code I ssh to the/a box and via expect script, then cd to a specific directory to get each service version / build id which is stored in a specific file at specific individual path for each service. There are chances that for some of the services the same file (having version / build information) may be stored at a different location in the box. So I have algo in app that in case attempt to get the details fails for the first path I will use other script to look for information at different path:
Main Block of code:
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);
}
}
Now I set all events for each spawned tasks:
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];
}
});
}
The issue is that after getting 11th console logs as mentioned below I see error:
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)
I tried adding 'process.setMaxListeners(0);' at many points in my code but still I keep seeing this error?
Any idea how can I solve this issue? Thanks in advance.