fix: die from SIGINT when interrupted on POSIX - #612
Open
mrpmohiburrahman wants to merge 1 commit into
Open
Conversation
Exiting normally is indistinguishable from a run that was never interrupted, so re-raise the signal instead and let the shell report 130.
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.
Fixes #470.
Pressing
^Cmade concurrently report success, soset -escripts carried on,&&chainscontinued, and cancelled CI steps went green.
The reason it reports 0 isn't that the wrong number is chosen — it's that concurrently ends via
process.exit(), which is a normal termination. A parent seesWIFEXITEDand has no way to tellit apart from a run that was never signalled. 130 isn't a value a process can return; it's what the
shell synthesises when it observes death-by-signal. So no change to the exit code could have fixed
this. @dimikot spelled this out in the issue thread as "method 3", and that's what this implements:
concurrently re-raises SIGINT on itself once the run is over.
You mentioned unix-based systems being the straightforward part, so this is gated on
process.platform !== 'win32'and Windows behaviour is untouched.What changed. A module-level flag set by a POSIX-only
process.once('SIGINT', ...), consumedinside the existing
exitProcessfunnel — the one #604 added sorestoreCodepage()always runsfirst.
oncematters: the listener detaches itself, so it can't swallow the signal that getsre-raised. Both the success and failure arms go through it, since a run that fails and gets
interrupted still died of
^C.The re-raise stays where
exitProcessalready sits, afterresultsettles.resultis the.finally(...)promise, so teardown commands have already run andKillOnSignalhas alreadydetached its own SIGINT listener — which is what lets the re-raised signal reach the default
disposition rather than being caught again.
kill-on-signal.tsis deliberately untouched. The rewrite of children's SIGINT exit codes to0 from #164 stays exactly as-is. This is only about concurrently's own status.
On the npm noise that motivated #164. That workaround existed to stop npm 5 printing
ELIFECYCLEon every^C, so it's fair to ask whether dying by signal brings it back. It doesn't— measured on npm 10.9.8 / Node 22, sending SIGINT to the process group of a real
npm run:Zero either way, and npm forwards 130 cleanly — matching what @dimikot predicted would happen.
Modern npm doesn't print the 2018 message for signal death at all, so #164's original rationale
doesn't apply to concurrently's own exit status.
Testing.
bin/index.spec.tsalready had a test sending a real SIGINT to a real spawned CLI andasserting
exit.codewas 0 — it was asserting the bug. Renamed, and re-asserted on{ code, signal }with a platform split, so POSIX expects
{ code: null, signal: 'SIGINT' }and Windows stays{ code: 0, signal: null }. I checked it actually guards the fix by revertingbin/index.tsaloneand confirming it fails with the bug's exact signature.
Also verified by hand:
^Cnow gives 130 where it gave 0; an interrupted run whose command hadalready failed also gives 130; and uninterrupted runs are unchanged (0 / 1 / 1 / 0 across success,
failure, mixed and
--success first).pnpm test— 640 passed (640), same as before the changepnpm test:smoke— 4 passed (4)pnpm typecheck,pnpm lint,pnpm format— cleanpnpm buildOne judgment call worth flagging: I added a three-line note to
docs/cli/success.md, since thatpage opens on exit codes mattering in CI and doesn't currently mention that
^Cbypasses--successentirely. Happy to drop it if you'd rather keep the diff tobin/.