fix(router-core): reset oldest pointer when evicting the sole LRU cache entry#7742
Open
FrancoKaddour wants to merge 1 commit into
Open
Conversation
…ntry When set() evicts the only entry in the LRU (oldest === newest), oldest.next is undefined so the if-branch that updated oldest was skipped. oldest retained a stale pointer to the deleted node while newest was correctly set to undefined. On the next set() call the stale oldest caused cache.delete() to operate on a key that no longer existed, leaving the new entry untracked by oldest. Repeated insertions then grew the cache beyond its max capacity. Fix: unconditionally assign oldest = toDelete.next so that when the evicted node has no successor, oldest becomes undefined.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe eviction logic in the LRU cache's ChangesLRU eviction fix
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
When
set()evicts the only entry in the LRU cache (oldest === newest), the node has nonextpointer, so the branch that updatedoldestwas never taken.oldestkept a stale reference to the deleted node whilenewestwas correctly set toundefined.On the next
set()call the staleoldestcausedcache.delete()to run against a key that no longer existed — leaving the new entry untracked byoldest. Subsequent insertions then grew the cache silently beyond its max capacity.Root cause
Fix
Test
Added a test case
respects max=1 across multiple replacementstolru.test.tsthat reproduces the bug and passes with the fix.Summary by CodeRabbit
Bug Fixes
Tests