Errors thrown inside of queue "completed" handler result in "Missing lock" errors
Created by: sysrun
This one gave me hours of pain...
Description
If an error is throw inside the queue "completed" handler, the queues "error" event will be triggered with "Error: Missing lock for job failed" and errorMessage "Error processing job".
Minimal, Working Test code to reproduce the issue.
After the second iteration the described error will be triggered
const bull = require('bull');
const queue = bull('testqueue', 'redis://localhost:6380');
queue.process(async (job) => {
console.log('>> processing', job.id);
return Promise.resolve(true);
});
queue.on('completed', (job, result) => {
console.log('>>> completed', job.id);
if (job.data.counter >= 2) {
console.log('>>> counter >= 2, throwing inside "completed" handler');
throw Error();
}
});
queue.on('error', (error, errorMessage) => {
console.error('error', error);
console.error('errorMessage', errorMessage);
});
let counter = 0;
setInterval(() => {
const job = queue.add({counter: counter++});
console.log('> added job', job.id);
}, 1000);
Bull version
4.1.0