chore: when dev server restarts, ensure exiting the parent process kills child process (#8703)

This commit is contained in:
Alessio Gravili
2024-10-14 14:02:26 -06:00
committed by GitHub
parent e3957d746b
commit f1ebf56691
2 changed files with 25 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ import { loadEnv } from 'payload/node'
import { getNextRootDir } from './helpers/getNextRootDir.js'
import { runInit } from './runInit.js'
import { safelyRunScriptFunction } from './safelyRunScript.js'
import { child, safelyRunScriptFunction } from './safelyRunScript.js'
import { createTestHooks } from './testHooks.js'
const prod = process.argv.includes('--prod')
@@ -59,6 +59,15 @@ await nextDev({ port }, 'default', rootDir)
void fetch(`http://localhost:${port}${adminRoute}`)
// This ensures that the next-server process is killed when this process is killed and doesn't linger around.
process.on('SIGINT', function () {
process.on('SIGINT', () => {
if (child) {
child.kill('SIGINT')
}
process.exit(0)
})
process.on('SIGTERM', () => {
if (child) {
child.kill('SIGINT')
}
process.exit(0) // Exit the parent process
})