Solvedbull Missing lock for job


It works awesome! How are you?
But the problem is, that we have 4 deployments and every deployments has 8 processes which is 32 processes and if it always creates a new connect to Redis, it runs out of connections.
I tried doing this like this (re-use Redis connections):

var opts = {
  prefix: `${global.ngivr.config.redis.scope}queue`,
//  redis: global.ngivr.config.redisUrl,
//  /*
  createClient: function (type) {
    switch (type) {
      case 'client':
        return global.ngivr.redis;
      case 'subscriber':
        return global.ngivr.redisSubscriber;
        return new Redis(global.ngivr.config.redis);
//  */

 kues[named] = Queue(named, opts);

But I always get this error:

failedReason: 'Missing lock for job 1 finished' } Error: job stalled more than allowable limit

I am using ioredis.

Do you know what it could be the problem?


39 Answers

✔️Accepted Answer

We also have this issue, but without any specific configuration (just host and port), no custom redis client, and no prefix.
We have a simple winston log on workers completed event, no exception and no long running task in the event handler.

Error: Missing lock for job repeat:myjob:00f4c548cdc615774bd5dce8f54394ec:1591048800000 failed
    at Function.finishedErrors (/app/node_modules/bullmq/src/classes/scripts.ts:203:16)
    at Job.moveToFailed (/app/node_modules/bullmq/src/classes/job.ts:312:23)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at handleFailed (/app/node_modules/bullmq/src/classes/worker.ts:286:9)
    at (/app/node_modules/bullmq/src/classes/worker.ts:137:27)

Other Answers:

FWIW, this was happening to me when I had upgraded to 3.x but forgot to clear the existing queues from Redis, so they were still in the 2.x format.

This error seems to be related to running a long running operation in the on('completed') event handler.
I had this before:

queue.on('completed', (job, result) => {
    logger.debug('job completed with result: ',  result)
    socketController.notify(, {status: 'completed'})

The socketController.notify() line was sending a message over websockets to clients. I was getting the Missing lock for job error every single time. I tried many different things to no avail.

Then I moved the notify() line from this callback into the queue.process() function at the end of that, when the job was done processing, leaving just the debug() line in the completed handler. The error went away.

Another user reported this error going away after commenting out lines using queue events: here

For anyone experiencing this issue it might be worth removing any substantial code from the on('complete') handler.

More Issues: