Why is node.js memory leak when restarting redis

If you run the code below and restart the redis server, you will get one or two uncaughtException, but no more errors, and then, the memory will grow very quickly, I want to know why and how to solve this problem.

/** * 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); }) 
+4
source share
1 answer

Probably node_redis queues the commands in it offline_queue . You can check redis.offline_queue.length and possibly stop issuing commands whenever it is too large or something like that. See also node_redis documentation ( offline_queue search).

+3
source

Source: https://habr.com/ru/post/1398975/


All Articles