Repository navigation
fix(server): roll back earlier rate-limit layers when a subsequent layer denies (#1002) - #1331
Open
harrymove-ctrl wants to merge 1 commit into
Open
harrymove-ctrl wants to merge 1 commit into
harrymove-ctrl wants to merge 1 commit into
Conversation
Collaborator
Author
|
@ducnmm This PR is ready for review. Summary of changes:
|
2 tasks done
harrymove-ctrl
force-pushed
the
fix/issue-1002-rate-limit-layer-rollback
branch
from
October 29, 2026 04:32
11cf093 to
892304d
Compare
Collaborator
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1002
rate_limit_middlewarechecks three sliding-window rate-limit layers in sequence:rate:dk:{public_key})rate:{owner})rate:hr:{owner})Previously, each layer called
check_and_record_windowindependently, which immediately addedweightZSET members ({request_id}:0 .. {request_id}:{weight-1}) before subsequent layers were evaluated. When Layer 2 (account_burst) or Layer 3 (account_sustained) denied a request, the entries already written to earlier layers were never removed (despite the comment in the Layer-2 denial branch stating that the delegate-key entry was rolled back). As a result, account-level denials permanently drained the caller's per-delegate-key quota for the remainder of the 60-second window and caused subsequent requests in the same minute to fail withlayer: "delegate_key".Changes
check_and_record_window_with_idandrollback_window_entries(ZREMover{request_id}:0 .. {request_id}:{weight-1}) inservices/server/src/rate_limit.rs.check_write_rate_limit_windowsfor the 3-layer authenticated write path:account_burst) denies or errors, rolls back the Layer-1 (rate:dk:{public_key}) entries recorded for thatrequest_id.account_sustained) denies or errors, rolls back both Layer-1 (rate:dk:{public_key}) and Layer-2 (rate:{owner}) entries recorded for thatrequest_id.account_burst_and_sustained_denials_roll_back_earlier_layersandaccount_burst_denial_does_not_spend_delegate_key_budget_redis) verifyingZCARDand layer attribution across single-weight and multi-weight endpoints.Test Plan
cargo test --manifest-path services/server/Cargo.toml --bins rate_limit(50 passed, 0 failed)