2012-10-22 32 views
1

我读过的this question答案,试了很多办法来解决我的问题,但不能 - 因此张贴从我身边这个查询。节点JS可能EventEmitter内存泄漏检测

基本上我有服务的一个数组列表 - 这涉及到〜1500在其他不同的盒子,在我的应用程序的NodeJS运行运行数字。按我的代码,我ssh到/盒和通过expect脚本,然后cd到一个特定的目录来获得每个服务版本/构建其在每个服务特定个人的路径保存在一个特定的文件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);'在我的代码中的许多点,但我仍然看到这个错误?

任何想法,我怎么能解决这个问题呢?提前致谢。

回答

2

你有一个错字。的child[i]代替child[id]

您因此设置在每个createChildEvents调用同一个发射器的监听器。

+0

感谢您指出了这一点 - 它固定我的问题。 process.on('exit',function(code)to(child [id])。process.on('exit',function(code) – Prakash

+0

你在这个问题上做了改变 - (child [i]不应该根据答案改变你的问题,以保持它与未来的读者寻找相同的答案相关。 –

+1

请注意,我已经恢复相应的变化 – Prakash