I don't think your code is to blame. I had the very same issue using kue, to be sure that I wasn't doing anything wrong I made a super simple worker like this:
var Redis = require('redis'),
kue = require('kue'),
config = require("../../config/local.js"),
redisClient = Redis.createClient(config.redis),
jobs = kue.createQueue({ redis : config.redis });
jobs.process('testjobs', function processJob(job, done, error) {
console.log(job.data, error);
done();
});
Running this code made me realize that is kue the one that leaks. The workaround is to use pm2, this guy will run your program and restart it if the memory is going to the roof, I'm using the JSON App Declaration to configure a maximum amount of memory allowed before restarting the process.
{
"apps" : [
{
"name": "test_worker",
"script": "test.js",
"instances": 1,
"max_restarts": 10,
"max_memory_restart" : "10M",
"ignore_watch": [
"[\\/\\\\]\\./",
"node_modules"
],
"merge_logs": true,
"exec_interpreter": "node",
"exec_mode": "fork_mode"
}
]
}
Hope this helps.