Skip to content

Commit

Permalink
Fix memory watcher reboot (#54760)
Browse files Browse the repository at this point in the history
I've introduced a bug with memory watching in development in this PR: #53523.

Specifically when calling `cleanup` the process would exit because the `exit` listener on the childprocess would be called which then calls `process.exit(0)`. This caused a condition where calling `worker.end()` would immediately quit the process.

This PR ensures the cleanup listeners for childprocess are disabled (`.off(`) so that when we call `worker.end()` the process is terminated without the main process being terminated.
  • Loading branch information
timneutkens committed Aug 30, 2023
1 parent 59e3ffa commit 842366c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/next/src/cli/next-dev.ts
Expand Up @@ -193,6 +193,12 @@ async function createRouterWorker(fullConfig: NextConfigComplete): Promise<{
return {
worker,
cleanup: async () => {
// Remove process listeners for childprocess too.
for (const curWorker of ((worker as any)._workerPool?._workers || []) as {
_child?: ChildProcess
}[]) {
curWorker._child?.off('exit', cleanup)
}
process.off('exit', cleanup)
process.off('SIGINT', cleanup)
process.off('SIGTERM', cleanup)
Expand Down

0 comments on commit 842366c

Please sign in to comment.