fix: harden cli signal and control-fd handling#236
Open
covercrust wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the srt CLI’s lifecycle handling around control-fd config streaming and child-process termination, aiming to make cleanup more reliable and exit statuses more conventional.
Changes:
- Parses
--control-fdwith an explicit base-10 radix and skips setup when the parsed value is invalid. - Switches to
process.oncefor exit/signal handlers and ensures the control-fd stream is destroyed during exit cleanup. - Preserves conventional signal exit codes (
128 + signal) and runs sandbox cleanup on child processerroras well asexit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
60
to
64
| .option( | ||
| '--control-fd <fd>', | ||
| 'read config updates from file descriptor (JSON lines protocol)', | ||
| parseInt, | ||
| (val: string) => parseInt(val, 10), | ||
| ) |
Comment on lines
+187
to
+193
| const sigNum: Record<string, number> = { | ||
| SIGINT: 2, | ||
| SIGTERM: 15, | ||
| SIGHUP: 1, | ||
| SIGQUIT: 3, | ||
| } | ||
| const exitCode = 128 + (sigNum[signal] ?? 1) |
Author
|
Concrete repro scenarios for review:
Validation used for this PR:
|
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.
Why
This tightens a few shutdown and control-fd edge cases in
src/cli.tsthat make the CLI harder to reason about during failure/interruption paths:--control-fd abccurrently parses toNaNand still enters the control-fd pathSIGINT/SIGTERMcurrently exit with0, which hides interruption from callersprocess.on(...)instead ofprocess.once(...)errorpath does not currently callcleanupAfterCommand()What changed
--control-fdwith an explicit radix:parseInt(val, 10)NaNprocess.on(...)toprocess.once(...)128 + signalSandboxManager.cleanupAfterCommand()in the childerrorhandler tooReviewer guide
This PR is intentionally narrow:
src/cli.tsConcrete repro
1. Invalid control-fd input
Run:
node dist/cli.js --control-fd abc -c 'echo hello'Before:
parseInt('abc')becomesNaNAfter:
2. SIGINT exit code
Run:
node dist/cli.js -c 'sleep 30'Then press
Ctrl+C.Before:
0After:
130(128 + SIGINT)Validation
npx tsc --noEmitnpm run buildRisk
Low. The patch is isolated to CLI argument validation and shutdown/error cleanup behavior.