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

Turbopack Dev Server Hangs Indefinitely With CPU Spin When Stdout Pipe Reader Exits

When the stdout of `next dev` (Turbopack) is piped to a reader that exits early (e.g., `head -N`), subsequent requests hang forever and the process consumes CPU (~1.3 cores) in a native spin. The server stops responding while TCP connections are accepted but never answered.

highConfidence 75%Next.jsAffected V16.2.11Affected V16.3.0-Canary.96

Origin Analysis

Turbopack's native logging writes to stdout without handling broken pipe (EPIPE) errors. When the pipe reader exits, write calls fail or block in a way that causes a busy loop on the native side (likely retrying the write or spinning on a lock), consuming CPU and eventually blocking request processing.
1. Install dependencies (pnpm install). 2. Start dev server with early-exiting stdout pipe: `npx next dev -p 3111 2>&1 | head -15 &` 3. Send repeated requests: `for i in $(seq 1 30); do curl -s -o /dev/null -m 10 -w "#$i -> %{http_code}\n" http://localhost:3111/; done` Observe that after ~11 requests, all requests time out (000) and the process spins CPU without serving.

Fixing Code Block

Edge Case Audit

This fix suppresses log output after the pipe breaks, which may hide important logs if stdout is later restored (unlikely). On some platforms, broken pipe errors may not be immediately delivered, leading to a small window where writes still block. Ensure the atomic flag is used consistently across all logging paths to avoid mixed behavior. Rollback: revert to previous logging implementation if this causes missing logs in critical scenarios.

Ecosystem Topology