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 0000000000..a38e6b515a --- /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 1c2b8f45b1..cd8c0c52e9 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());