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

MemoryStore: prevent race condition #49542

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

pjambet
Copy link
Contributor

@pjambet pjambet commented Oct 8, 2023

Motivation / Background

It looks like #46305 accidentally removed the synchronize block that would prevent a race conidition where two threads would read the same value and only a single increment/decrement would take effect as they would both write the same value.

Detail

This was discussed in this PR where the original fix for the expiry was being backported to 7.0

Additional information

Doesn't look like it's easy to deterministically test this. All I could do was to spin multiple threads and sometimes see inconsistencies, but not always

That comment shows how I played with it locally to exacerbates the behavior with sleep calls: #49503 (comment)

Since 7.1 was just released, do we need a different PR to backport this to 7-1-stable?

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

It looks like rails#46305 accidentally removed the synchronize block that
would prevent a race conidition where two threads would read the same
value and only a single increment/decrement would take effect as they
would both write the same value.
@pjambet pjambet force-pushed the pj/fix-memory-store-race-condition branch from 812bdad to 7f2e0ff Compare October 8, 2023 17:57
@zzak zzak added this to the 7.1.1 milestone Oct 9, 2023
@zzak zzak requested review from byroot and removed request for byroot October 9, 2023 00:01
@byroot byroot merged commit a385d7b into rails:main Oct 9, 2023
4 checks passed
byroot added a commit that referenced this pull request Oct 9, 2023
…tion

MemoryStore: prevent race condition
@byroot
Copy link
Member

byroot commented Oct 9, 2023

Thanks, backported to 7-1-stable as well: 52c4aef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants