Skip to content

Commit

Permalink
Handle duplicate signals
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jul 9, 2024
1 parent d7a49d5 commit e94b7e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,20 @@ export async function startServer(

try {
const cleanupListeners = [() => new Promise((res) => server.close(res))]
let cleanupStarted = false
const cleanup = () => {
debug('start-server process cleanup')
if (cleanupStarted) {
// We can get duplicate signals, e.g. when `ctrl+c` is used in an
// interactive shell (i.e. bash, zsh), the shell will recursively
// send SIGINT to children. The parent `next-dev` process will also
// send us SIGINT.
return
}
cleanupStarted = true
;(async () => {
debug('start-server process cleanup')
await Promise.all(cleanupListeners.map((f) => f()))
debug('start-server process cleanup finished')
process.exit(0)
})()
}
Expand Down

0 comments on commit e94b7e6

Please sign in to comment.