AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js 16.2.2 Standalone With CacheComponents: Cached Internal Streamed Fetches Cause Unbounded ArrayBuffers Growth And OOM

Under sustained high-cardinality traffic, Next.js standalone server with cacheComponents enabled and cached internal server-side fetch to streamed JSON routes retains ArrayBuffers indefinitely, leading to unbounded memory growth and eventual OOM crash.

highConfidence 85%Next.jsRoute Handlersnext buildAffected V16.2.2

Origin Analysis

The Cache Components feature caches the entire response body of internal server-side fetch requests in memory as ArrayBuffers. For streamed responses, the full stream is buffered before being cached. In standalone mode, the cache lacks effective eviction or size limits for high-cardinality keys, so each unique request path creates a new cache entry that is never reclaimed, causing memory accumulation until the heap is exhausted.
1. Clone https://github.com/mdotk/next-standalone-memory-repro and run npm install. 2. Build with npm run build. 3. Start standalone server: PORT=3025 npm run start:standalone. 4. Run load generator: BASE_URL=http://127.0.0.1:3025 DURATION_MS=180000 CONCURRENCY=64 PAGE_WEIGHT_KB=2048 API_WEIGHT_KB=2048 MIX=page,api,page,page MAX_LOGGED_FAILURES=20 npm run load. 5. Observe memory via curl 'http://127.0.0.1:3025/api/health?sample=1' and note rss/arrayBuffers growth until OOM.

Fixing Code Block

Edge Case Audit

This workaround disables caching for the specific fetches, which may increase latency and load on the origin server for those requests. It should be used only until an official Next.js fix is available. If you need caching for streamed responses, consider implementing a bounded LRU cache at the application level. Rollback is straightforward: remove the wrapper and revert to the original fetch calls. Monitor memory usage after applying.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state