Graceful Shutdown
How the Nuxt and Next.js storefront servers drain in-flight requests on SIGTERM, and the environment variables that control the delay and drain timeout.
When a storefront pod is descheduled, Kubernetes sends SIGTERM and keeps routing traffic to the pod until the load balancer notices it is gone. Without a controlled shutdown, requests that are still in flight - or that arrive in that window - fail with HTTP 502.
The Nuxt and Next.js storefront servers shut down gracefully on SIGTERM:
- The server keeps serving for a short delay, so the load balancer can stop sending it new requests.
- It stops accepting new connections and closes idle keep-alive connections.
- It waits for every in-flight request to finish.
- It exits with code
0. Requests still open when the drain timeout passes are closed, and the process exits anyway.
SIGINT is not affected: yarn dev and a local Ctrl+C still stop the server right away.
Prerequisites
Next.js requires @vue-storefront/next and @alokai/cli from the release that introduced this feature, because the Docker image loads a preload script shipped by @vue-storefront/next. Nuxt requires the matching @vue-storefront/nuxt release.
Configuration
Both storefronts read the same environment variables, in milliseconds:
| Variable | Default | Description |
|---|---|---|
ALOKAI_SHUTDOWN_DELAY_MS | 5000 | How long the server keeps accepting connections after SIGTERM. |
ALOKAI_SHUTDOWN_DRAIN_TIMEOUT_MS | 15000 | How long in-flight requests get to finish before they are closed. |
Keep ALOKAI_SHUTDOWN_DELAY_MS + ALOKAI_SHUTDOWN_DRAIN_TIMEOUT_MS below the pod's terminationGracePeriodSeconds (30 seconds by default). Past that, Kubernetes sends SIGKILL and the drain is cut anyway.
Invalid or negative values fall back to the defaults.
How it is wired
- Nuxt:
@vue-storefront/nuxtregisters a Nitro server plugin. It turns off Nitro's ownSIGTERMhandling and runs the drain above, then calls Nitro'sclosehook. Nitro keeps handlingSIGINT. SetNITRO_SHUTDOWN_DISABLED=1to opt out. - Next.js: the image built by
alokai deploystarts the server withnode --require ./graceful-shutdown.cjs server.js. The preload comes from@vue-storefront/next/graceful-shutdown, setsNEXT_MANUAL_SIG_HANDLE=trueto replace Next.js' built-in handler (which has no timeout and exits with code143), and runs the drain. If you build your own image, copy that file next toserver.jsand keep the--requireflag.