From aa92b3361c28ffe7cdc3b24feb80d345d0141722 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 2 May 2025 09:52:58 -0400 Subject: [PATCH] fix(core): update fork task runner so it propagates exit signals (#30998) This is a fix when using the TUI `forked process-task-runner`. The `SIGINT` and other signals are not handled, which causes the underlying process (in this case `run-executor`) to be left hanging. ## Current Behavior TUI leaves processes hanging when using `forked-process-task-runner` ## Expected Behavior TUI should kill processes ## Related Issue(s) Fixes # --- packages/nx/src/tasks-runner/fork.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/nx/src/tasks-runner/fork.ts b/packages/nx/src/tasks-runner/fork.ts index 4c5c9db22c..a8aa72846e 100644 --- a/packages/nx/src/tasks-runner/fork.ts +++ b/packages/nx/src/tasks-runner/fork.ts @@ -1,6 +1,7 @@ import { fork, Serializable } from 'child_process'; import { join } from 'path'; import { PseudoIPCClient } from './pseudo-ipc'; +import { signalToCode } from '../utils/exit-codes'; const pseudoIPCPath = process.argv[2]; const forkId = process.argv[3]; @@ -35,3 +36,18 @@ childProcess.on('exit', (code) => { pseudoIPC.close(); process.exit(code); }); + +// Terminate the child process when exiting +process.on('exit', () => { + childProcess.kill(); +}); +process.on('SIGINT', () => { + childProcess.kill('SIGTERM'); + process.exit(signalToCode('SIGINT')); +}); +process.on('SIGTERM', () => { + childProcess.kill('SIGTERM'); +}); +process.on('SIGHUP', () => { + childProcess.kill('SIGTERM'); +});