fix race-condition in scheduler thread #30
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andtrigger.nextFireTime.millis
after we've called watch.The fast thread will have updated the
trigger.nextFireTime
so that it's now different from thejobData.score
that we've read before calling watch.Fixes #29