From 5b8c1434e24c8b65cca29f72e6c0d2d9cc8d159d Mon Sep 17 00:00:00 2001 From: guru-bharadwaj20 Date: Sat, 28 Nov 2026 16:47:30 +0530 Subject: [PATCH] [node-core-library] Handle SIGHUP in SubprocessTerminator SubprocessTerminator only hooked SIGINT, SIGTERM and exit. Detached children live in their own session, so when the terminal closes and the parent gets SIGHUP, the children never see the hangup and keep running. Treat SIGHUP like the other two signals. --- .../subprocess-terminator-sighup_2026-11-28-12-00.json | 10 ++++++++++ .../node-core-library/src/SubprocessTerminator.ts | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 common/changes/@rushstack/node-core-library/subprocess-terminator-sighup_2026-11-28-12-00.json diff --git a/common/changes/@rushstack/node-core-library/subprocess-terminator-sighup_2026-11-28-12-00.json b/common/changes/@rushstack/node-core-library/subprocess-terminator-sighup_2026-11-28-12-00.json new file mode 100644 index 00000000000..a38e6b515a5 --- /dev/null +++ b/common/changes/@rushstack/node-core-library/subprocess-terminator-sighup_2026-11-28-12-00.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/node-core-library", + "comment": "Handle SIGHUP in `SubprocessTerminator` the same way as SIGINT and SIGTERM, so detached child processes are cleaned up when the terminal is closed.", + "type": "patch" + } + ], + "packageName": "@rushstack/node-core-library" +} diff --git a/libraries/node-core-library/src/SubprocessTerminator.ts b/libraries/node-core-library/src/SubprocessTerminator.ts index 1c2b8f45b1a..cd8c0c52e91 100644 --- a/libraries/node-core-library/src/SubprocessTerminator.ts +++ b/libraries/node-core-library/src/SubprocessTerminator.ts @@ -48,7 +48,7 @@ const _isWindows: boolean = process.platform === 'win32'; * that the child gets terminated when the current process terminates. * * @remarks - * This works by hooking the current process's events for SIGTERM/SIGINT/exit, and ensuring the + * This works by hooking the current process's events for SIGTERM/SIGINT/SIGHUP/exit, and ensuring the * child process gets terminated in those cases. * * SubprocessTerminator doesn't do anything on Windows, since by default Windows automatically @@ -166,6 +166,7 @@ function _ensureInitialized(): void { process.prependListener('SIGTERM', _onTerminateSignal); process.prependListener('SIGINT', _onTerminateSignal); + process.prependListener('SIGHUP', _onTerminateSignal); process.prependListener('exit', _onExit); } @@ -178,6 +179,7 @@ function _cleanupChildProcesses(): void { process.removeListener('SIGTERM', _onTerminateSignal); process.removeListener('SIGINT', _onTerminateSignal); + process.removeListener('SIGHUP', _onTerminateSignal); const trackedSubprocesses: ITrackedSubprocess[] = Array.from(_subprocessesByPid.values());