From 842366c92cedabd1b31c89e3782915d625f3860a Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 30 Aug 2023 10:58:44 +0200 Subject: [PATCH] Fix memory watcher reboot (#54760) 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. --- packages/next/src/cli/next-dev.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/next/src/cli/next-dev.ts b/packages/next/src/cli/next-dev.ts index 780a89e3f3f1..765bdf051d1f 100644 --- a/packages/next/src/cli/next-dev.ts +++ b/packages/next/src/cli/next-dev.ts @@ -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)