Self-Healing CI: Recovering a CDN Cold Cache 504
A 504 from a CDN on the first request to an uncached path is a slow origin fetch, not a broken asset -- once the edge has warmed the object, the same request succeeds.
The problem
A post-deploy check fails with a 504 Gateway Timeout from the CDN because the requested path was not cached and the edge’s origin fetch was slow on the first hit. The asset and origin are fine; the cold-cache fetch took too long once. A human re-runs and, with the object now warm at the edge, the request returns 200 unchanged.
HTTP/1.1 504 Gateway Timeout
# first request to an uncached path; edge origin-fetch timed out, then warms the cacheWhy it happens
On a cache miss the CDN edge fetches the object from origin before serving it, and that first cold fetch can be slow enough to time out as a 504, even though the asset and origin are healthy and every subsequent request is served fast from the warm edge.
It is a cold-cache origin-fetch blip, not a broken asset: once the edge has the object cached, the same request succeeds, so a retry returns 200.
The manual fix
Manual mitigations for a cold-cache 504:
- Re-run the check after the edge has warmed the object.
- Pre-warm critical paths after deploy so the first real request is not a cold miss.
- Add retry-with-backoff around post-deploy checks that hit the CDN.
How this gets automated
A cold-cache 504 is distinguishable from a real origin outage by whether the request recovers once the edge warms the object. A self-healing CI pipeline detects the gateway-timeout-on-cold-cache condition, retries after the edge warms, and only escalates if the request keeps timing out, which is the real signal of a genuine origin problem rather than a cold fetch.