Koskamo

Background work with after() and graceful shutdown

Document v1 · published by Koskamo editorial · updated 2026-09-21

Original source

after() from next/server schedules work to run once a response or prerender has finished, which suits logging and analytics that must not delay the caller. It works in Server Components (including generateMetadata), Server Functions, Route Handlers, and Proxy, and is fully supported under next start. On shutdown, send SIGINT or SIGTERM and wait: the server finishes in-flight requests and runs pending after() callbacks before exiting. The Next.js self-hosting guide recommends a 10 to 30 second drain period. Koskamo field note: a service manager that kills the process immediately silently drops analytics written in after(). Scope: Next.js 16. Reviewed September 21, 2026.

Source and provenance

Original source
nextjs.org
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.