Skip to content

Null cache entries have size 0, preventing LRU eviction #89033

@iMUngHee

Description

Contributor

Link to the code that reproduces this issue

https://github.com/iMUngHee/nextjs-lru-memory-leak

To Reproduce

  1. npm install --ignore-scripts
  2. npm run build && npm start
  3. node test-memory-leak.mjs (sends 50k requests with unique IDs)
  4. Take heap snapshot of the server process
  5. Search for LRUNode - count matches request count

Current vs. Expected behavior

Current:
LRUNode instances grow unbounded. Each unique dynamic route path creates a new entry that never gets evicted.

Expected:
LRU cache should evict old entries when reaching maxSize (1MB).

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:31 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 11
Binaries:
  Node: 23.4.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 9.12.3
Relevant Packages:
  next: 16.2.0-canary.8 // Latest available version is detected (16.2.0-canary.8).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Route Handlers, Performance

Which stage(s) are affected? (Select all that apply)

Other (Deployed), next start (local)

Additional context

I am running version 15.5.9 with self-hosting, and while investigating the cause of memory leaks, I discovered that LRUNode instances were accumulating abnormally in heap dumps.

Activity

added theissue type on Jan 26, 2026
github-actions

github-actions commented on Feb 10, 2026

Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

locked as resolved and limited conversation to collaborators on Feb 10, 2026
cdostan

Add a comment

This conversation has been locked and limited to collaborators.
Remember, contributions to this repository should follow its contributing guidelines, security policy and code of conduct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformanceAnything with regards to Next.js performance.Route HandlersRelated to Route Handlers.locked

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Notifications

      You're not receiving notifications from this thread.

      Participants

      @timneutkens@iMUngHee

      Issue actions