Repository navigation
[node-core-library] Handle SIGHUP in SubprocessTerminator - #6235
Open
Guru R Bharadwaj (guru-bharadwaj20) wants to merge 1 commit into
Open
Guru R Bharadwaj (guru-bharadwaj20) wants to merge 1 commit into
Guru R Bharadwaj (guru-bharadwaj20) wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the SIGHUP child-process cleanup change.
No open issues 🎉
What changed in this PR
Addresses #6124 by extending SubprocessTerminator to clean up tracked child processes on SIGHUP, preventing detached children from surviving terminal closure.
Changes:
- Registers and removes a SIGHUP listener alongside SIGINT and SIGTERM, reusing the existing termination handler.
- Updates the API remarks to list SIGHUP.
- Adds a patch change entry for
@rushstack/node-core-library.
| File | Description |
|---|---|
libraries/node-core-library/src/SubprocessTerminator.ts |
Adds SIGHUP handling and updates the documented event list. |
common/changes/@rushstack/node-core-library/subprocess-terminator-sighup_2026-11-28-12-00.json |
Records the fix for a patch release. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6124
If a tool that uses
SubprocessTerminatoris running in a terminal and the terminal is closed, the tool gets SIGHUP and exits, but its child processes keep running. On Linux and macOSRECOMMENDED_OPTIONSsetsdetached: true, so the children are in their own session and never get the hangup, andSubprocessTerminatoronly listened for SIGINT, SIGTERM andexit.I added SIGHUP next to SIGINT and SIGTERM in
_ensureInitialized()and remove it again in_cleanupChildProcesses().Details
SIGHUP goes through the same
_onTerminateSignalhandler: the tracked process trees are killed, then the signal is re-sent to the current process with our listener removed, so the process still exits the way it would on SIGHUP without the listener.The listener is registered on every platform, like the existing SIGINT/SIGTERM ones. Node supports listening for SIGHUP on Windows (it fires when the console window is closed), but I only tested the behavior on Linux.
No API change. I also updated the
@remarkstext that lists the hooked events.How it was tested
rush build --to @rushstack/node-core-libraryandrush test --only @rushstack/node-core-libraryboth pass.@rushstack/node-core-library@5.25.3and ran the script from the issue (spawnsleep 1000withRECOMMENDED_OPTIONSand register it withkillProcessTreeOnExit), then sent the parent a signal.kill -HUPthe parent exits andsleepkeeps running. SIGTERM and SIGINT kill it.lib-commonjs/SubprocessTerminator.jsreplaced by the build from this branch,sleepis killed for SIGHUP, SIGTERM and SIGINT, and the parent exits in all three cases.I added a change file with
type: patch.