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

ratelimits: Use INCRBY instead of SET when a bucket already exists #7782

Merged
merged 6 commits into from
Nov 4, 2024

Conversation

jprenken
Copy link
Contributor

@jprenken jprenken commented Nov 1, 2024

Add a new method, BatchIncrement, to issue IncrBy (instead of Set) to Redis. This helps prevent the race condition that allows bursts of near-simultaneous requests to, effectively, spend the same token.

Call this new method when incrementing an existing key. New keys still need to use BatchSet because Redis doesn't have a facility to, within a single operation, increment or set a default value if none exists.

Add a new feature flag, IncrementRateLimits, gating the use of this new method.

CPS Compliance Review: This feature flag does not change any behaviour that is described or constrained by our CP/CPS. The closest relation would just be API availability in general.

Fixes #7780

@jprenken jprenken requested a review from a team as a code owner November 1, 2024 20:56
@jprenken jprenken requested a review from jsha November 1, 2024 20:56
Copy link
Contributor

github-actions bot commented Nov 1, 2024

@jprenken, this PR appears to contain configuration and/or SQL schema changes. Please ensure that a corresponding deployment ticket has been filed with the new values.

Copy link
Contributor

github-actions bot commented Nov 1, 2024

@jprenken, this PR adds one or more new feature flags: IncrementRateLimits. As such, this PR must be accompanied by a review of the Let's Encrypt CP/CPS to ensure that our behavior both before and after this flag is flipped is compliant with that document.

Please conduct such a review, then add your findings to the PR description in a paragraph beginning with "CPS Compliance Review:".

@jprenken jprenken marked this pull request as draft November 1, 2024 20:57
@letsencrypt letsencrypt deleted a comment from github-actions bot Nov 1, 2024
@jprenken jprenken marked this pull request as ready for review November 1, 2024 21:49
jsha
jsha previously approved these changes Nov 1, 2024
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Looks good to me. A couple of optional quibbles on comments.

ratelimits/limiter_test.go Outdated Show resolved Hide resolved
ratelimits/source_redis.go Outdated Show resolved Hide resolved
aarongable
aarongable previously approved these changes Nov 2, 2024
Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Looks good, will approve again when tests pass.

@beautifulentropy beautifulentropy changed the title Rate limits: replace redis SET with INCRBY ratelimits: Use INCRBY instead of SET when a bucket already exists Nov 4, 2024
@jprenken jprenken merged commit 4adc65f into main Nov 4, 2024
18 checks passed
@jprenken jprenken deleted the batchincrement branch November 4, 2024 19:20
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.

Rate limits: replace redis SET with INCRBY
4 participants