proxy: make rate limiting atomic and update-safe - #268
Draft
hieblmi wants to merge 12 commits into
Draft
Conversation
hieblmi
force-pushed
the
fix/rate-limiter-review
branch
from
August 12, 2026 15:11
8914d84 to
b85c195
Compare
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
Motivation
The limiter previously protected individual cache operations, but a request matching multiple rules was not an atomic operation. Concurrent requests for the same client could interleave reservations and refunds, allowing partial quota consumption. Cache identity was also based on the path expression, which collapsed distinct rules that intentionally used the same expression with different horizons.
Runtime service updates prepared caller-owned service and rule objects before publication. Reusing those pointers could race active limiter matching, expose partially prepared state after a failed update, and reset cache observability before the replacement was known to be valid. The freebie path also tallied its quota before knowing whether the limiter would admit the request.
Impact
Commit structure
The changes are split by independently reviewable issue and ordered by
dependency:
proxy: validate rate limit configurationsconstructing unusable limiters
proxy: reset rate limit state on service reusewhen re-preparation fails
proxy: keep duplicate rate limit rules independentdifferent horizons
proxy: make multi-rule admissions atomic per clientmatching rule rejects
proxy: release finalized rate limit admission stateor cancellation
proxy: fail closed on undersized rate limit cachesrefresh bursts
proxy: expose metrics for distinct rate limit rulescounter behavior
proxy: rate limit zero-priced requestsproxy: coordinate freebie and rate limit reservationswhen freebie persistence fails
proxy: publish service updates from isolated snapshotsproxy: track cache metrics for active limiter snapshotsproxy: document and verify rate limiter enforcement scopekeying
Validation
go test -race -p 1 ./...go vet ./...git diff --check