2012-02-29 9 views
4

以下のコードを実行してサーバーを再起動すると、uncaughtExceptionが1つまたは2つありますが、もうエラーはなくなります。理由と方法を知りたい再起動時にnode.jsのメモリリークが発生する理由

/** 
* This code will memory leak, if you restart redis server when the node process is running 
* 
* @author Gui Lin 
*/ 
var redis = require('redis').createClient(); 

setInterval(function(){ 

    redis.multi() 
    .zrangebyscore('timeup', 0, Date.now()) 
    .zremrangebyscore('timeup', 0, Date.now()) 
    .exec(function(err, data) { 
      if(err) console.log(err.stack); 
      if(data) data = data[0]; 
     }); 
}, 1); 

process.on('uncaughtException', function(err) { 
    console.log(err.stack); 
}) 

答えて

3

それはそれでコマンドをキューイングするoffline_queuenode_redisおそらくです。 redis.offline_queue.lengthをチェックして、それが大きくなりすぎたときなど、いつでもコマンドの発行を停止することができます。 node_redis documentationoffline_queueを検索)も参照してください。

関連する問題