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

Dev Server 500S On Every Request: Concurrent GetStaticPaths Corrupts Prerender-Manifest.Json

Concurrent getStaticPaths executions under the same dynamic segment perform unsynchronized read-modify-write on prerender-manifest.json. Non-atomic writes leave the file invalid JSON, causing persistent 500s across all routes in dev server.

highConfidence 95%Next.jsAffected V16.2.7Affected V16.3.0-Canary.97

Origin Analysis

packages/next/src/server/dev/next-dev-server.ts performs unsynchronized read-modify-write on prerender-manifest.json. Two concurrent requests read the same manifest, mutate different routes, and write back with a non-atomic writeFile. Depending on interleaving, a shorter write truncates a longer one, leaving partial JSON or trailing bytes.
1. Clone https://github.com/LouisTsang-jk/nextjs-prerender-manifest-race 2. npm install 3. ./repro.sh (starts next dev, requests 10 pages under app/[locale]/ concurrently, then checks manifest and issues a request) 4. Observe 500 responses with SyntaxError: Unexpected end of JSON input or Unexpected non-whitespace character after JSON.

Fixing Code Block

Edge Case Audit

This lock is in-process only; if multiple Next.js dev server processes or workers share the same .next directory, lost updates may still occur. Rollback: remove .next/dev/prerender-manifest.json or restore from backup; the patch can be reverted by unapplying the diff. The atomic rename uses a unique temp file, but concurrent cross-process writes are not serialized; consider a filesystem lock if multi-process dev is used.

Ecosystem Topology