Skip to content

Instantly share code, notes, and snippets.

@jamesholcomb
Last active August 18, 2021 11:58
Show Gist options
  • Save jamesholcomb/99f5ccff117cb14b39c932e3d4d93dab to your computer and use it in GitHub Desktop.
Save jamesholcomb/99f5ccff117cb14b39c932e3d4d93dab to your computer and use it in GitHub Desktop.
bullmq missing lock repro
import IORedis from "ioredis"
import { Queue, QueueScheduler, Job, Worker } from "bullmq"
const main = async (): Promise<void> => {
const qs = new QueueScheduler("Paint", {
connection: new IORedis(),
})
const qPaint = new Queue("Paint", {
connection: new IORedis(),
defaultJobOptions: {
removeOnComplete: true,
removeOnFail: true,
},
})
const worker = new Worker(
"Paint",
async (job: Job): Promise<number[]> => {
console.log(`worker: ${job.id} ${job.queueName} ${job.data.foo}`)
return []
},
{
connection: new IORedis(),
}
)
worker.on("completed", (job: Job, result: number[]) => {
if (job.id === "house3") {
// cause unhandled rejection
throw new Error("oops")
}
console.log(`completed ${job.id}`, result.slice(0))
})
await qPaint.waitUntilReady()
const addJob = async (q: Queue, id: number): Promise<void> => {
const j = await q.add(
"house",
{ foo: "bar" },
{ delay: 1000, jobId: "house" + id }
)
console.log(`added job ${j.id} on queue ${j.queueName}`)
}
let id = 0
setInterval(() => {
if (id < 5) {
id++
addJob(qPaint, id)
}
}, 1000)
}
main()
/*
127.0.0.1:6379> keys bull:Paint*
1) "bull:Paint:meta"
2) "bull:Paint:delay"
3) "bull:Paint:id"
4) "bull:Paint:events"
added job house1 on queue Paint
added job house2 on queue Paint
worker: house1 Paint bar
completed house1 []
added job house3 on queue Paint
worker: house2 Paint bar
completed house2 []
added job house4 on queue Paint
worker: house3 Paint bar
Error: Missing lock for job house3. failed
at Function.finishedErrors (/Users/jamesholcomb/code/bull-mq-test/node_modules/bullmq/dist/classes/scripts.js:144:24)
at Job.moveToFailed (/Users/jamesholcomb/code/bull-mq-test/node_modules/bullmq/dist/classes/job.js:292:41)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async handleFailed (/Users/jamesholcomb/code/bull-mq-test/node_modules/bullmq/dist/classes/worker.js:255:17)
at async Worker.retryIfFailed (/Users/jamesholcomb/code/bull-mq-test/node_modules/bullmq/dist/classes/worker.js:401:24)
at async Worker.run (/Users/jamesholcomb/code/bull-mq-test/node_modules/bullmq/dist/classes/worker.js:112:34)
added job house5 on queue Paint
worker: house4 Paint bar
completed house4 []
worker: house5 Paint bar
completed house5 []
127.0.0.1:6379> keys bull:Paint*
1) "bull:Paint:meta"
2) "bull:Paint:delay"
3) "bull:Paint:id"
4) "bull:Paint:house3"
5) "bull:Paint:events"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment