Calling queue.add from within sandboxed process causes job to be repeated forever
Created by: leontastic
I stumbled upon an interesting bug as I was trying to trigger processing jobs from within sandboxed processes. I made a repository with a minimal reproducible example: https://github.com/leontastic/bull-sandbox-bug
Here's the code:
// queues.js
const Queue = require('bull')
const REDIS_ENDPOINT = 'redis://127.0.0.1:6379'
module.exports.queue1 = new Queue('queue1', REDIS_ENDPOINT)
module.exports.queue2 = new Queue('queue2', REDIS_ENDPOINT)
module.exports.queue3 = new Queue('queue3', REDIS_ENDPOINT)
// index.js
const path = require('path')
const { queue1, queue2, queue3 } = require('./queues')
queue1.process(path.join(__dirname, '/sandboxed1.js'))
queue2.process(path.join(__dirname, '/sandboxed2.js'))
queue3.process(path.join(__dirname, '/sandboxed3.js'))
queue1.on('active', () => console.log('queue1 active'))
queue1.on('completed', () => console.log('queue1 completed'))
queue2.on('active', () => console.log('queue2 active'))
queue2.on('completed', () => console.log('queue2 completed'))
queue3.on('active', () => console.log('queue3 active'))
queue3.on('completed', () => console.log('queue3 completed'))
queue1.add({})
// sandboxed1.js
const { queue2 } = require('./queues')
module.exports = function (job) {
return queue2.add({}).then(() => job.data)
}
// sandboxed2.js
const { queue3 } = require('./queues')
module.exports = function (job) {
return queue3.add({}).then(() => job.data)
}
// sandboxed3.js
module.exports = function (job) {
return Promise.resolve(job.data)
}
Here's the output I'm expecting:
queue1 active
queue2 active
queue1 completed
queue3 active
queue2 completed
queue3 completed
Here's the output I get:
queue1 active
queue2 active
queue1 completed
queue2 completed
queue2 active
queue2 completed
queue2 active
queue2 completed
queue2 active
queue2 completed
queue2 active
queue2 completed
queue2 active
queue2 completed
...repeated forever
Does anyone know what's going on here? It seems like bull gets confused about which queue I want to add my job to in sandboxed2.js
, but I have no explanation for the subsequent behaviour.