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 between set() and push() #14

Merged
merged 2 commits into from
Oct 24, 2024
Merged

Conversation

gwynne
Copy link
Member

@gwynne gwynne commented Oct 24, 2024

A worker can end up picking up a job between set() and push(), causing a race condition that results in the job running twice. This PR fixes the race by adding an initial state for jobs that haven't yet been pushed.

There is no test included because I couldn't work out a clean way to reliably test for the race.

Fixes #13.

Thanks to @sterien7 for reporting, and to @sidepelican for the excellent analysis of the problem in the original bug report against the old version of the driver!

@gwynne gwynne added the bug Something isn't working label Oct 24, 2024
@gwynne gwynne requested review from 0xTim, MahdiBM and ptoffy October 24, 2024 07:22
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (4e31dfa) to head (439ab86).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
+ Coverage   98.47%   98.54%   +0.07%     
==========================================
  Files           7        7              
  Lines         262      275      +13     
==========================================
+ Hits          258      271      +13     
  Misses          4        4              
Files with missing lines Coverage Δ
Sources/QueuesFluentDriver/FluentQueue.swift 96.93% <100.00%> (+0.16%) ⬆️
Sources/QueuesFluentDriver/JobModel.swift 100.00% <ø> (ø)

... and 3 files with indirect coverage changes

Copy link

@sidepelican sidepelican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw the changes carefully, and I think it's fine.

@gwynne gwynne merged commit 20ebbf1 into main Oct 24, 2024
9 checks passed
@gwynne gwynne deleted the fix-double-job-run branch October 24, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Jobs sometimes executed multiple times.
4 participants