Skip to content

Commit

Permalink
Add NEXT_MANUAL_SIG_HANDLE handling to start-server.ts (#59117)
Browse files Browse the repository at this point in the history
If a manual signal handler is registered, SIGINT and SIGTERM should not
be handled by Next.js. This was already the case in the standalone
server.js but was missing here, rendering the env flag useless.

With this fix, the example given in
https://nextjs.org/docs/pages/building-your-application/deploying#manual-graceful-shutdowns
is working (again).

Fixes #56810.

Co-authored-by: Zack Tanner <[email protected]>
  • Loading branch information
mdio and ztanner authored Dec 1, 2023
1 parent a5e60f1 commit cdff6df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ export async function startServer(
console.error(err)
}
process.on('exit', (code) => cleanup(code))
// callback value is signal string, exit with 0
process.on('SIGINT', () => cleanup(0))
process.on('SIGTERM', () => cleanup(0))
if (!process.env.NEXT_MANUAL_SIG_HANDLE) {
// callback value is signal string, exit with 0
process.on('SIGINT', () => cleanup(0))
process.on('SIGTERM', () => cleanup(0))
}
process.on('rejectionHandled', () => {
// It is ok to await a Promise late in Next.js as it allows for better
// prefetching patterns to avoid waterfalls. We ignore loggining these.
Expand Down

0 comments on commit cdff6df

Please sign in to comment.