Repository navigation
fix(bash): kill the command's whole process group on timeout, cancel and drop - #278
Merged
Merged
Conversation
…and drop On Unix, bash leads its own process group (process_group(0)); a GroupKill guard, declared after the child so it fires before the child is reaped, killpg's the group on timeout, cancel or drop and is disarmed when the command finishes on its own. Pipeline stages, && lists and background jobs no longer outlive a cancelled call; a setsid process still escapes. Windows unchanged. libc is a cfg(unix) dependency (already in the tree). Closes #277. Suggested by @shahidcodes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
…se docs - std's CommandExt::process_group (Rust 1.64) instead of tokio's, which needs tokio 1.40 while the crate asks for tokio = "1". - The command is outside the terminal's foreground group, so the terminal's Ctrl+C no longer reaches it: examples/cli.rs now aborts the run on Ctrl+C during a run (exits only at the prompt); documented, with /dev/tty prompts. - Docs: a background job survives a finished command only if its output is redirected; one holding the pipes keeps the call open until the timeout. - Cargo.toml: the unix block no longer splits the wasm32 comment. - Tests: a zombie counts as gone (no init in a container). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG
Merged
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.
Closes #277 (suggested by @shahidcodes).
Before: a timeout or cancel killed only the
bashprocess (kill_on_drop); pipeline stages,&&lists and background jobs kept running.Now (Unix):
bashis spawned withprocess_group(0). AGroupKillguardkillpgs the whole group with SIGKILL on timeout, cancel, or when the call's future is dropped. It is declared after the child, so it fires before the child is reaped — the pgid cannot have been reused. When the command finishes on its own, the guard is disarmed: a detached background job it started deliberately (a dev server) survives. Only a process that callssetsidescapes. Windows is unchanged.Dependency:
libcundercfg(unix)(already in the tree through tokio). This is the crate's firstunsafeblock — onekillpgcall with a SAFETY comment.Tests (
tests/tools_test.rs, Unix): timeout, cancel, and drop each kill a background job and a pipeline; a finished command leaves its detached job alone. Mutation-checked: withoutprocess_group(0)the three kill tests fail; withoutdisarm()the last one fails. Full suite: 1516 passed. Docs:docs/concepts/tools.mdcaveat, CLAUDE.md, CHANGELOG.🤖 Generated with Claude Code
https://claude.ai/code/session_01T7iq5hpndSiHQcnAsywKuG