Skip to content
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

fix race-condition in scheduler thread #30

Closed

Conversation

bp-FLN
Copy link
Contributor

@bp-FLN bp-FLN commented Jan 9, 2019

There is a race-condition in JesqueSchedulerService#acquireJobs which seems to be caused if the scheduler threads have different latencys to the redis instance.

So 2 threads are getting the same job from Trigger.TRIGGER_NEXTFIRE_INDEX.
Since we only call watch after that, if one server is so fast that it called watch and executed the transaction, the other thread may not have called watch yet and so doesn't see that the fast thread already aquired and executed the job. The slow thread then calls watch and executes his transaction, causing the scheduled job to be enqueued a second time.

This patch fixes this issue by comparing jobData.score and trigger.nextFireTime.millis after we've called watch.
The fast thread will have updated the trigger.nextFireTime so that it's now different from the jobData.score that we've read before calling watch.

Fixes #29

@bp-FLN bp-FLN closed this Dec 20, 2021
@bp-FLN bp-FLN deleted the fix-race-condition branch December 20, 2021 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scheduled job enqueued twice
1 participant