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

Turbopack Persistent Cache Poisoning Causes Worker Panic, Deadlock, And OOM Crash Loop

A corrupted Turbopack persistent cache (missing persistent_task_type) triggers a panic in tokio workers, leading to deadlocked compiles, high CPU spin (600-975%), and eventual OOM crash loops. The self-invalidation marker is not consistently honored, causing the poisoned cache to persist across restarts.

criticalConfidence 92%Next.jsAffected V16.2.6

Origin Analysis

The turbo-tasks backend assumes every restored task has a persistent_task_type. When the cache is corrupted (e.g., torn write during SIGKILL/OOM), the field is None, causing an unrecoverable panic at turbopack/crates/turbo-tasks-backend/src/backend/operation/mod.rs:966. The engine lacks validation to gracefully handle invalid cache entries, and the PANIC invalidation marker is not respected in all conditions.
1. Obtain a poisoned Turbopack persistent cache (e.g., from a torn write, or use the provided reproduction repo). 2. Run `next dev`. 3. Observe tokio worker panics: 'Every task must have a task type'. 4. Any HTTP request hangs; CPU spins at 600-975% while idle; RSS grows from 1 to 4.8 GB until OOM. 5. Restart repeats the cycle because the poisoned DB remains on disk. Workaround: `rm -rf .next/dev/cache/turbopack`.

Fixing Code Block

Edge Case Audit

This fix may cause cold builds (slower first compilation) when cache corruption occurs. Concurrency concerns: multiple workers may encounter the same corrupt entry simultaneously, leading to redundant invalidations; invalidation must be idempotent and thread-safe. The broader cache invalidation mechanism (both per-task and global) must be verified to avoid race conditions. Rollback suggestion: disable persistent caching (if possible) or manually clear the cache directory. Test across different versions and platforms, as the exact cache layout may vary.

Ecosystem Topology