# One timeout, nine failed deploys: a broken Turbopack cache and a slot that never rotates

> I kept the Turbopack compile cache to speed up deploys. One evening a postcss subprocess timed out under load, then 9 deploys in a row failed on the same error. Failure never rotated the slot.

- Date: 2026-11-29
- Topics: Next.js, DevOps
- Chinese original: https://kbs0830.com/blog/turbopack-cache-poisoned-deploy

This site runs on my desktop at home. After a push to `main`, the GitHub Actions runner on that desktop runs the deploy script: it runs `next build` inside a clean copy, `.live`, building into **the slot that is not currently live** (`.next-a` and `.next-b` alternate), and swaps over only after a health check passes. If a build fails, the live slot is not affected at all and the site keeps serving.

In the early hours of 11/29 I made a speed-up: the deploy used to delete the whole slot before every build, including Turbopack's compile cache (`.next-x/cache`), so the log always said `No build cache found`. I changed it to "delete everything except `cache`", and with the two slots alternating, each slot can use its cache every other deploy.

Before that, 33 deploys that day had succeeded, none failed, and each of the two slots had built several times with the cache. From 18:15 that evening, deploys failed 9 times in a row, and until the fix at 19:00, none of the 10 commits pushed went live.

## The same error every time

```
./.live/src/app/globals.css
Error: Node.js subprocess crashed while evaluating loaders [postcss]: failed to receive message

Caused by:
- Node.js process is still running or its exit status is unavailable
- reading packet length
- timeout while receiving message from process
- deadline has elapsed
```

When Turbopack processes CSS, it starts a Node.js subprocess to run postcss (which is what Tailwind relies on). The error means the main process waited for the subprocess to reply until it timed out.

## The first time: the machine really was full

At 18:15 I had several Claude Code sessions open at once, each building and running tests. The desktop CPU was at 100%, there were 86 to 150 node processes, about 2.4 GB of memory was available, and even Git Bash had fork failures.

The deploy log shows how slow it was: Next.js startup alone took 2 minutes, and `Running next.config.ts`, normally 0.5 seconds, took 24.6 seconds that time. Ten minutes into the compile stage, the postcss subprocess timed out and the build failed.

Up to here it is all reasonable: the machine was busy, so it timed out.

## Afterward: load recovered, and it still kept failing

After that, every push failed, and failed faster and faster:

| Attempt | commit | `next.config.ts` | Compile time before failing |
|---|---|---|---|
| 1 | `b153933` | 24.6 s | 605 s |
| 2 | `539cd10` | 7.1 s | 143 s |
| 3 | `332eab5` | 1.0 s | 15 s |
| 4 | `7a517c7` | 0.53 s | 17 s |
| 5 | `7a517c7` | 0.43 s | 2.9 s |
| 6 | `7a517c7` | 0.51 s | 3.1 s |
| 7 | `a942232` | 0.47 s | 18.7 s |
| 8 | `a942232` | 0.56 s | 2.8 s |
| 9 | `6d39e38` | 0.59 s | 4.7 s |

The key is the second column. How long `next.config.ts` takes basically reflects how busy the machine is; from attempt 3 on it was back to the usual 0.5 seconds, which means the load had recovered long before. The last column was still failing, and in the end failing within 3 seconds. **3 seconds cannot really be "waiting for a subprocess until it times out"**; it looks more like the build getting "this step failed before" as its result from the start.

And the same commit, built in another worktree with a different output folder (`NEXT_DIST_DIR=.next-test`, without that cache), passed. The code was fine.

## Why it kept breaking in the same place

Putting three things together explains it:

1. **A failure does not rotate the slot**: when a build fails there is no swap, so live is still `.next-a`, and the next deploy's target is **still `.next-b`**
2. **The cache goes with the slot**: the early-morning speed-up meant `.next-b/cache` was no longer deleted
3. So for attempts 2 to 9, **every deploy read the same cache left behind by the failure in attempt 1**

The benefit of the two-slot deploy was "a failure does not affect live", but it also means the slot that failed keeps getting reused. If the cache is not deleted, that slot carries the state from the last failure forever.

## Verification: clear the cache and it passes

After deleting `.live/.next-b/cache/turbopack` and rerunning the same commit (`6d39e38`):

- the log showed `No build cache found` again
- `Compiled successfully in 46s`, and the deploy succeeded at 19:02
- there were about 108 node processes then, about the same as during the failures, so it did not pass because the load had dropped

After that, `.next-b` built once more using the new cache, and compiled in 24.4 seconds. So keeping the cache is not itself wrong: 46 seconds without cache, 24 seconds with.

## The fix: on failure, clear that slot's cache and build once more

`scripts/deploy.ps1`:

```powershell
node (Join-Path $repo "node_modules\next\dist\bin\next") build 2>&1 | ForEach-Object { Log "  $_" }
$buildExit = $LASTEXITCODE
$cacheDir = Join-Path $targetPath "cache"
if ($buildExit -ne 0 -and (Test-Path $cacheDir)) {
    Log "[WARN] build failed (exit $buildExit), clearing the cache of $targetSlot and building again from scratch"
    Remove-Item $targetPath -Recurse -Force
    node (Join-Path $repo "node_modules\next\dist\bin\next") build 2>&1 | ForEach-Object { Log "  $_" }
    $buildExit = $LASTEXITCODE
}
```

If the first failure was due to a broken cache, the second build from scratch passes; if the code really has an error, the second one fails the same way and just costs one more build time (about 46 seconds). Deploys will no longer get stuck on the same cache.

## What I did not work out

- **I did not take apart what exactly was broken inside the cache.** "Turbopack stored the failed result in the cache" is inferred from the table above, not confirmed by reading the source
- **Whether the first 10-minute failure was a real load timeout, or the cache was already bad then**, I cannot tell. `.next-b` had already built successfully several times that day with the preserved cache (for example at 17:57 and 18:03), so whether the cache went bad during those 10 minutes or earlier cannot be told from the log

## A side note: I also blocked a deploy myself

After the fix, I also edited `deploy.ps1` in the live folder, not yet committed, and saw that another session had already pushed the same fix. Within those few seconds, the next deploy started. A deploy first makes the live folder `git merge --ff-only` to the latest version, and my uncommitted `deploy.ps1` blocked it:

```
error: Your local changes to the following files would be overwritten by merge:
	scripts/deploy.ps1
```

This is only a warning and does not stop the deploy (the build reads the clean copy `.live`). But the scheduled tasks (monitoring, backup) run the `scripts\` in the live folder, and they would keep using the old version. There is now a hook: **directly editing git-tracked files in the live folder is blocked**, so to edit, open your own worktree.

## What I learned

- **A cache that is left behind after a failure must have a "clear it on failure" way out.** Especially in blue-green or two-slot deploys where a failure does not switch, the slot that failed will certainly be reused
- **To tell whether load is the cause, look at the load-related numbers within the same build.** Here it was the time of `next.config.ts`: it had recovered and the error was still there, so the problem was not load
- **If the same error keeps appearing and it fails faster each time, suspect the cache first.** A real timeout only gets slower, never faster

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/turbopack-cache-poisoned-deploy
