fix: refresh redis-quota concurrency TTL to prevent over-admission (#335) - #336
Merged
Merged
Conversation
…lm-d#335) Concurrency-mode redis-quota tracks in-flight requests as an INCR/DECR counter, but set the key's EXPIRE only on the first acquire (new_val==1) and never refreshed it. The TTL equals window (factory default 1m; the multitenant overlays don't set it). Under sustained per-tenant load the counter stays positive, so ~window seconds after it first went positive the key expires mid-flight, the counter resets to 0, and further requests are admitted beyond the limit -- over-admission up to 'limit' extra concurrent per tenant, recurring every window (and for any request in flight longer than window). This is the correctness residual after llm-d#311/llm-d#334: llm-d#334 made the counter accurate (retries no longer leak INCRs), but an accurate-but-positive counter was still wiped by the TTL. - Refresh EXPIRE on every acquire so the counter cannot expire while there is activity; the key now expires only after window of total inactivity (crash-orphan cleanup). - Refresh EXPIRE on release while reservations remain in flight. - Add a regression test (TTL refresh across interleaved acquires) that fails before this change and passes after. Rate-limit mode is unchanged (its sorted set expires per-member correctly). Closes llm-d#335 Signed-off-by: Shimi Bandiel <shimib@google.com>
shimib
requested review from
RishabhSaini,
ahg-g,
evacchi and
jtechapps
as code owners
July 21, 2026 19:14
…-admission fix) Signed-off-by: Shimi Bandiel <shimib@google.com>
jtechapps
reviewed
Jul 23, 2026
jtechapps
approved these changes
Jul 23, 2026
This was referenced Jul 23, 2026
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.
What / why
Fixes #335 (sibling of #311/#334). In
RedisQuotaGateconcurrency mode (pkg/redis/quota_gate.go), the in-flight counter'sEXPIREwas set only on the first acquire (new_val == 1) and never refreshed. The TTL =window(factory default 1m; multitenant overlays don't set it), so under sustained per-tenant load the key expires mid-flight, the counter resets to 0, and further requests are admitted beyondlimit— recurring everywindow, and for any request in flight longer thanwindow.This is the correctness residual after #334: that PR made the counter accurate (retries no longer leak
INCRs), but an accurate-but-positive counter was still wiped by the TTL.Changes (
pkg/redis/quota_gate.go,acquireConcurrency)EXPIREon every acquire (drop thenew_val == 1guard) — the counter can't expire while there's activity; the key now expires only afterwindowof total inactivity (crash-orphan cleanup).EXPIREon release while reservations remain in flight.TestRedisQuotaGate_Concurrency_TTLRefresh(TTL refresh across interleaved acquires viaminiredisFastForward) — fails onmain, passes with the fix.Rate-limit mode is unchanged (its sorted set expires per-member correctly).
Testing
go test ./pkg/redis/...green (new + existing quota tests).mainand pass with the fix.producer.TestMultipleTenantsIsolationflake is pre-existing and in a different, untouched module.)Closes #335