-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Duplicate job scheduler tasks #2876
Comments
Just tested with the deprecated Repeatable job interface using a const {Worker, Queue} = require('bullmq');
const {setTimeout, setInterval} = require('timers/promises');
const connection = {
host: '127.0.0.1',
password: 'password',
};
async function run() {
const queue = new Queue('test', {
connection,
});
await queue.waitUntilReady();
const worker = new Worker(
'test',
async () => {
await setTimeout(250);
},
{connection},
);
await worker.waitUntilReady();
for await (const _ of setInterval(50)) {
console.log('###');
await queue.add('test', undefined, {
repeat: {every: 100, key: 'test'},
});
console.log('active', await queue.getActiveCount());
console.log('waiting', await queue.getWaitingCount());
console.log('delayed', await queue.getDelayedCount());
}
}
run().catch((error) => {
console.error(error);
process.exit(1);
}); |
Hi, I've attached a screenshot showing a job that frequently duplicates, along with the options for the first two instances below.
|
Same issue with our setup. |
Encountering the same issue here. |
I have a grasp on why this is happening particularly when using very tight repetitions and many distributed calls to upsertJobScheduler. I am designing a solution for this now. |
Version
5.21.2
Platform
NodeJS
What happened?
We use BullMQ Job Scheduler to trigger frequent tasks (multiple per second). We leverage the
schedulerId
to ensure one task is only defined once. We have however observed that on some occasions tasks are not properly deduplicated and we end up with multiple instances of the repeated task. In our specific case we triggerupsertJobScheduler
at startup and have seen this ocure when having crash loops causing many restarts in a short period of time.How to reproduce.
I have written this JS script which pushes BullMQ to its limits. It goes beyond what we expect from it, but provides a reliable way to reproduce the bug that we are reporting here. Run the script and wait a few dozen seconds, you should see the counter for
waiting
tasks go up (restarting the script seems to help too).I've tried deep diving into the BullMQ code and debug logging at various places, but I'm yet unsuccessful in identifying the root cause of this duplication.
When there is no
Worker
involved, the duplication does not happen. I'm therefore suspecting that it could be triggered when the task is being processed by the worker when the upsert happens.Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: