process doesn't terminate on `queue.close()`
Created by: Ilaiwi
Hi,
I am using a queue to execute some jobs using child process. After all jobs are completed I want to close the queue and kill the child process responsible for executing the job.
according to the src
calling queue.close()
will send a signal to kill the child process
https://github.com/OptimalBits/bull/blob/master/lib/process/child-pool.js#L56
But in action, this doesn't happen and the process becomes a zombie process long after I closed the queue.
I debugged the src and what I figured out that the signal sent to the child process to kill is 0
(which doesn't kill the process) and there is no way to send another signal.
https://github.com/OptimalBits/bull/blob/master/lib/process/child-pool.js#L51
Am I doing something wrong or is it a bug?
src to reproduce:
index.js
var Queue = require('bull');
var process = require('process')
const qPromise = new Queue('test promisesss', {
redis:{
port: 6379,
host: 'localhost',
},
});
qPromise.process(__dirname+'/process')
qPromise.add({notification_id:"1",total:100, current:0},{
// jobId: "-1",
})
qPromise.add({notification_id:"2",total:200, current:0},{
// jobId: "-2",
})
qPromise.add({notification_id:"4",total:300, current:0},{
// jobId: "-3",
})
qPromise.on('completed', function(job, result){
console.log("job complete", job.id, result)
Promise.all([qPromise.getWaitingCount(),qPromise.getActiveCount()]).then( ([waitingCount,activeCount]) => {
if(!waitingCount+activeCount){
console.log("draiiiin")
qPromise.close()
}
})
})
process.js
var Queue = require('bull');
var process = require('process')
const qPromise = new Queue('test promises', {
redis:{
port: 6379,
host: 'localhost',
},
});
console.log('processID ', process.pid)
module.exports = async function executeJob(job){
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(job.data)
resolve(job.data.total)
}, 1000);
})
}