Menu

A 503 that could not happen: finding a Fastify lifecycle bug
📰

A 503 that could not happen: finding a Fastify lifecycle bug

DEV Community: fastify·rokaskve·1 day ago
#xpZ8h6zN
#devtofastify#devto#dev#reply#handler
Long article (2556 words) — no AI summary yet.
Reading 0:00
15s threshold

We shipped a change that signs our render links with a secret held in the server environment instead of a value stored in the database. It has a guard: if the secret is missing, refuse to issue a link rather than fall back to something weaker. The guard returns 503 .

Then production returned a 503 for a request that should never have reached that guard — and the body attached to it belonged to a different response entirely.

POST / v1 / render - link ( invalid API key )

HTTP / 2 503 { "error" : "unauthorized" , "message" : "Invalid API key" }

Enter fullscreen mode

Exit fullscreen mode

A 503 status carrying a 401 body. That combination is not supposed to be constructible. This is how it happened, including the four attempts to reproduce it that all failed, and the Fastify behaviour underneath.

Reading the mismatch

The body is unambiguous: "Invalid API key" is the string our authentication middleware sends. Our global error handler has its own wording for a missing key — "Missing API key.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.