How a Lockfile-Only Cache Key Shipped a Node 18 Native Module Into a Node 20 Image and Crash-Looped Every Pod
11:04 UTC. Argo CD shows the billing-api rollout stuck at 1 of 6 pods ready. The new pods are
in CrashLoopBackOff, restart count 7 and rising. Staging was green forty minutes ago.
the scramble
Meera is on call. She pastes the first line of the pod log into the incident channel:
108 is Node 18, 115 is Node 20. The only change in the release was a one-line Dockerfile edit,
FROM node:18-slim to FROM node:20-slim, part of the runtime upgrade we had planned
for the quarter. The rollout strategy kept the five old pods serving, so customers saw nothing. That bought
us time. It did not buy an answer.
First theory, from Arjun: the base image tag is wrong and something is still pulling Node 18. We ran
docker run --rm billing-api:7f3c1e2 node -v and got v20.11.1. The image runs Node 20.
The module inside it was built for 18. So the question was how a Node 20 image ended up with Node 18 binaries.
the hunt
Second theory: the Dockerfile runs npm ci in the build stage, so maybe the build stage still
used a cached Node 18 layer. Docker's layer cache keys on the instruction text and the parent layer, and
the parent layer changed with the FROM line. We rebuilt locally with --no-cache and the
image started fine. That ruled out the registry and the Dockerfile's own layers, but the CI image still failed.
So CI was doing something the local build was not.
Third theory: a bad bcrypt release. We checked npm ls bcrypt in both builds. Same version,
5.1.1, same integrity hash in package-lock.json. Dead end, and a useful one, since it meant
the lockfile was identical between the good and bad builds.
I opened the workflow file. The pipeline does not run npm ci inside Docker. A previous
optimisation, from about a year ago, installs dependencies on the runner with actions/cache and
then does COPY node_modules ./node_modules in the Dockerfile to save ninety seconds of build time.
The cache key is the hash of package-lock.json and nothing else. The lockfile did not change in
this release, so the key matched an entry written on the last day the runner used Node 18. The step
restored a node_modules directory with bcrypt_lib.node compiled for ABI 108, skipped
npm ci, and the Dockerfile copied it into a Node 20 image.
the find
Native addons are compiled at install time against the Node headers that are present. A cache key that
ignores the Node version, the CPU architecture and the OS treats node_modules as plain data.
With bcrypt, sharp or better-sqlite3 in the tree, it is machine code for one specific runtime.
Why did staging pass? Staging deploys from a different workflow that runs npm ci inside the
image build, so it never touched the cache. Only the production workflow used the shortcut. We confirmed
by listing the caches:
The "Cache restored successfully" line is the whole incident. The step reported a hit, the install was skipped, and nothing in the job log suggested anything was off. The build was green for 11 minutes before Argo noticed the pods.
the fix
Immediate: roll back the Argo application to the previous image and delete the stale cache so the next run rebuilt it.
Durable: put the runtime into the key. Anything that changes what npm ci would produce has to be
part of the key, which means the Node version, the OS and the architecture. We also stopped copying
node_modules from the runner at all for the production image, since the ninety seconds were
not worth the failure mode.
Caching ~/.npm rather than node_modules keeps the download savings, and
npm ci still compiles native modules against whatever Node is actually in the image. We also
added a smoke step to the pipeline that runs the built image before pushing it:
the aftermath
Timeline: deploy at 10:53, first crash at 10:55, page at 11:04, rollback at 11:31, healthy at 11:34. About 41 minutes of a stuck rollout and zero customer-facing errors, because the old pods kept serving. The real cost was a blocked release train. Four other merges queued behind the broken one, and the Node 20 upgrade slipped two days.
- The smoke test would have failed the build at 10:52, a minute before the image was pushed.
- Staging and production now use the same Dockerfile path. The divergence between them is what hid the problem for a week of Node 20 testing.
-
The runbook for a crash loop right after a runtime bump now starts with
grep NODE_MODULE_VERSIONon the pod logs. -
Any workflow that caches
node_modulesdirectly now fails a lint check in the repo's workflow review checklist.
A lockfile says which packages to install. It says nothing about what they were compiled against, and a cache key built only from it will miss a runtime bump every time. I had read that workflow a dozen times and never noticed.