fix(start): forward signals to child and exit watcher on shutdown#3422
Merged
kamilmysliwiec merged 1 commit intoMay 1, 2026
Merged
Conversation
re-apply signal forwarding from prs nestjs#3313/nestjs#3338 that was reverted in 705bb7d, and explicitly exit when the spawned child exits during shutdown so the chokidar/tsc watcher does not keep the event loop alive. closes nestjs#3158 refs nestjs#3391
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: 3158
After the reverts that landed in v11.0.20 / v11.0.21 (commit
705bb7da),nest startno longer forwardsSIGINT/SIGTERMto the spawned child Node process. As a result, the application's asynchronous shutdown hooks (onModuleDestroy,beforeApplicationShutdown,onApplicationShutdown) never run when the user hits Ctrl+C, because the parent CLI process exits immediately and the child is killed by the terminal's signal broadcast before it can finish its shutdown sequence (or, when launched detached, is left orphaned).A closely related regression (#3391) makes
nest start --watchrequire two Ctrl+C presses before the process actually exits — the chokidar/tsc watcher keeps the parent's event loop alive after the child has already exited.What is the new behavior?
SIGINTandSIGTERMreceived by the CLI parent are now forwarded to the spawned child Node process, so async shutdown hooks run to completion before the process exits.exitevent and then propagates the same exit code, instead of returning immediately.shuttingDownflag tracks whether a shutdown signal has been received. In watch mode, when the child exits whileshuttingDownis true, the parent explicitly callsprocess.exit()so the watcher does not keep the event loop alive — fixing the double-Ctrl+C behavior reported in nest start --watch hangs on SIGINT since v11.0.17 #3391.process.onceto avoid double-handling on repeated signals, and the same handler tears down the watcher cleanly.This re-applies the fix from PRs #3313 / #3338 (which were reverted in
705bb7da) and folds in the watch-mode fix for #3391 in a single, minimal change.A new unit test file
test/actions/start.action.spec.tscovers:process.exitwhen child exits naturallyDoes this PR introduce a breaking change?
Other information
This PR also addresses #3391 (
nest start --watchrequires two Ctrl+C presses) — the sameshuttingDownflag used to forward signals is reused to short-circuit the watcher's keep-alive on shutdown, so both regressions are resolved by one change.