Self-hosting Next.js with graceful shutdown
Anyone self-hosting Next.js on places like Fly, Render, or Railway?
Need guidance on how to handle rolling deploys: how do I gracefully shutdown my app?
The default behavior with Next when receiving SIGINT or SIGTERM is to just quit the Next.js process with a 0 exit code. That’s nasty as it stops all work in requests that are in flight.
I’m trying to figure out is how to get a route handler that’s serving a request (especially crucial for webhooks processing, with Clerk or Stripe let’s say) to close out processing as part of that graceful shutdown, but new requests are refused.
Also want to close out any DB connections.
Not sure how to achieve that.
Anyone has any tips? I’m using App Router and Prisma.
0 Replies