Repository navigation
Conversation
evict() computes the number of entries to evict over the whole cache, including global specs, but global specs are never eviction candidates. When the cache holds more global specs than maxEntries (e.g. --quota_max_cache_entries=1 after one read and one write RPC), the loop indexes past the candidate list and panics in the goroutine started by GetTokens, which takes down the server. Cap the number of evictions at the number of candidates. Also report maxEntries, not minBatchSize, in the NewCachedManager error message for an invalid maxEntries.
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.
manager.evict()computes the number of entries to evict aslen(m.cache) - m.maxEntries, which counts global specs. But the eviction candidates exclude globals, because they are never evicted. If the cache holds more global entries thanmaxEntriesallows,evictsends up larger thanlen(buckets)and the loop panics withindex out of range. The panic happens in the goroutine started fromGetTokens, so it takes down the server.The quota interceptor requests
{Global, Read}and{Global, Write}(bothRefundable: true), so with--quota_max_cache_entries=1(or--mysql_quota_max_cache_entries=1with--mysql_quota_min_batch_size> 0) the log server crashes as soon as it has served one read and one write RPC.This change caps the number of evictions at the number of non-global candidates. It also fixes the
NewCachedManagererror for an invalidmaxEntries, which printedminBatchSizeinstead. Behaviour for other values is unchanged: the existingTestCachedManager_GetTokens_EvictsCache, which counts globals towardsmaxEntries, still passes.Side note, not changed here: the
NewCachedManagerdoc says maxEntries is the limit "apart from global quotas", while the flag help and the existing test treat it as the total number of cached specs. This PR keeps the current behaviour.Fixes #3945
Testing:
TestCachedManager_GetTokens_MaxEntriesBelowGlobalSpecs: panics (index out of range [1] with length 1) without the fix, passes with it.go test -race ./quota/cacheqm/andgo test ./quota/...pass;golangci-lint run ./quota/cacheqm/...reports 0 issues.Checklist
This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.