Unverified Commit cdff6df0 authored by Michael Diodone's avatar Michael Diodone Committed by GitHub

Add NEXT_MANUAL_SIG_HANDLE handling to start-server.ts (#59117)

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: 's avatarZack Tanner <zacktanner@gmail.com>
parent a5e60f17
...@@ -280,9 +280,11 @@ export async function startServer( ...@@ -280,9 +280,11 @@ export async function startServer(
console.error(err) console.error(err)
} }
process.on('exit', (code) => cleanup(code)) process.on('exit', (code) => cleanup(code))
if (!process.env.NEXT_MANUAL_SIG_HANDLE) {
// callback value is signal string, exit with 0 // callback value is signal string, exit with 0
process.on('SIGINT', () => cleanup(0)) process.on('SIGINT', () => cleanup(0))
process.on('SIGTERM', () => cleanup(0)) process.on('SIGTERM', () => cleanup(0))
}
process.on('rejectionHandled', () => { process.on('rejectionHandled', () => {
// It is ok to await a Promise late in Next.js as it allows for better // 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. // prefetching patterns to avoid waterfalls. We ignore loggining these.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment