[backport]: fix: ensure LRU cache items have minimum size of 1 to prevent unbounded growth#89134
Merged
[backport]: fix: ensure LRU cache items have minimum size of 1 to prevent unbounded growth#89134
Conversation
…ed growth (#89040) ### What? Prevent LRU cache unbounded growth by requiring `calculateSize` to return values > 0. ### Why? When `calculateSize` returned 0 (e.g., for `null` values in the filesystem route cache), items were never evicted because they didn't contribute to `totalSize`. This caused unbounded memory growth when handling dynamic routes like `/api/logs/[id]` where each unique ID created a new cache entry with size 0. ### How? 1. **LRUCache now throws an error if size ≤ 0** - This catches bugs at development time rather than silently masking them: ```typescript if (size <= 0) { throw new Error( \`LRUCache: calculateSize returned ${size}, but size must be > 0. \` + \`Items with size 0 would never be evicted, causing unbounded cache growth.\` ) } ``` 2. **Fixed filesystem.ts** - Null entries (negative cache) now return size 1 instead of 0: ```typescript if (!value) { // Null entries (negative cache) still need a non-zero size for LRU eviction return 1 } ``` 3. **Fixed next-dev-server.ts** - Static paths cache now uses `|| 1` instead of `?? 0`: ```typescript return JSON.stringify(value.staticPaths)?.length || 1 ```
Collaborator
Failing test suitesCommit: cae2095 | About building and testing Next.js
Expand output● add-missing-react-import › transforms correctly using "add-missing-react-import/missing-react-import-in-component" data
Expand output● app-dir-runtime-config-experimental-edge › transforms correctly using "app-dir-runtime-config-experimental-edge/basic" data |
ijjk
approved these changes
Jan 28, 2026
timneutkens
approved these changes
Jan 28, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backports: