fix(cache): evict entries when a key holds a single entry - #5737
Open
mcollina wants to merge 1 commit into
Open
Conversation
MemoryCacheStore's eviction used entries.splice(0, entries.length / 2). splice truncates a non-integer deleteCount toward zero, so for the common case of a single cached response per distinct key (entries.length === 1 -> 0.5) nothing was evicted. As a result maxSize and maxCount were never enforced and memory grew unboundedly as distinct URLs were cached. Use Math.ceil(entries.length / 2) so a single-entry key always evicts its entry, and add a regression test covering the one-entry-per-key case. Update the existing limit tests, which had encoded the buggy behavior of leaving the store full after overflow.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5737 +/- ##
==========================================
+ Coverage 93.47% 93.48% +0.01%
==========================================
Files 110 110
Lines 38908 38908
==========================================
+ Hits 36368 36374 +6
+ Misses 2540 2534 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
MemoryCacheStore's eviction used
entries.splice(0, entries.length / 2).splicetruncates a non-integerdeleteCounttoward zero, so in the common case of a single cached response per distinct key (entries.length === 1->0.5) nothing was evicted. As a resultmaxSizeandmaxCountwere never enforced and memory grew unboundedly as distinct URLs were cached.This changes the eviction to use
Math.ceil(entries.length / 2)so a single-entry key always evicts its entry, adds a regression test covering the one-entry-per-key case, and updates the existing limit tests that had encoded the buggy behavior of leaving the store full after overflow.Reported in GHSA-37v3-qqr5-gmgc.