Repository navigation
WIP: fix(kill): %jobspec delivers via killpg to the job's pgrp (#2624) - #2625
Conversation
|
Cluster delivery complete (code + pins, captain verifies):
|
队长验收裁定(2026-11-02 晚):1 绿 3 红——其中 1 红是真存量缺陷(已另立案 #2626),2 红待复现定性亲验环境:scrubbed_cargo、构建槽内、逐 stem 在场核对(并行 + 绿: 红 1 —
即流水线一段被杀后其余段被连带终止,是 master 存量缺陷(本 PR diff 不触流水线监督路径)。已按立案卫生另开 #2626(P1,挂 1.5.0),本钉即其回归钉(期望不用改)。 红 2/3 — 处置:本 PR 不合,修复轮同批处理三红(#2626 的修复可落本分支或独立 PR,钉不重复);修好后队长复验全 stem + 守卫再走 CI。 |
…Refs #2624) GNU kill.def's jobspec arm resolves the spec to the job's pgrp for a job-control job (`pid = IS_JOBCONTROL (job) ? j->pgrp : j->pipe->pid`, kill.def:241) and kill_pid's group arm delivers with a single killpg (jobs.c:4008), with a SIGCONT follow-up when a stopped job takes SIGTERM/SIGHUP (jobs.c:4009-4010) and set_job_running when it takes SIGCONT (jobs.c:4013-4018). rubash resolved the spec through the shared path to entry.pids.last() and signaled that one pid, so `kill -TERM %1` on a pipeline killed only the last stage and left the rest running; `kill -STOP %1`/`-CONT %1` likewise missed every other member and every child a member forked after spawn. execute_tracked_background_kill now takes a killpg arm for a jobspec that resolves to a job-control job (entry.job_control — the J_JOBCONTROL record — with a recorded pgrp): delivery via kill::send_signal_to_process_group (the primitive from #2623, cherry-picked onto this branch), the stopped-job SIGCONT follow-up for TERM/HUP, and note_kill_delivery per recorded member — the same deferred-mark bookkeeping as the shared-group walk arm. kill -0 probes the group and takes the killpg result as the verdict. Shared-group jobs keep the per-member walk (jobs.c pgrp == shell_pgrp arm); plain pid operands keep single-process delivery (kill.def:196 kill_pid (pid, sig, pid < -1)).
PTY pins (script(1) harness shape from the #2622 pins), kernel-state assertions via /proc / ps on the exact `sleep N` cmdlines: - kill -TERM %1 kills all three stages of a background pipeline (wait reports 143); pre-fix two stages kept sleeping. - kill -STOP %1 / -CONT %1 reach the unrecorded child of `sh -c 'sleep 47; echo …'` (state T, then S) — the child is in the job's pgrp but in no recorded pid list. - kill -STOP %1 stops BOTH stages of a two-stage pipeline, -CONT resumes both. - A plain-pid kill (kill -TERM $!) still hits exactly one process: the sibling stage survives running — the pid/jobspec boundary does not move. UNVERIFIED-BY-CAPTAIN: not run by the delivering cluster.
…own job (Refs #2624) Diagnosis (captain adjudication on PR #2625: STOP pins timed out under cargo test but passed instantly under a standalone script(1) replication): the defect was in this harness, not the product. * sleep_pids/job counting matched `^sleep N$` SYSTEM-WIDE. Foreign processes with the same cmdline — the captain's CI-watcher poll loops spawn a bare `sleep 45` pair every cycle — entered the counts nondeterministically (a probe latched onto the watcher pair's pgrp in 2 of 6 rounds), and once a pin panicked, its session LEAKED (PtySession had no Drop): a stopped `sleep 99` never expires and poisoned every later run in the binary. * The child pin's final assert (`status.code() == Some(0)` after bare `exit`) was not GNU-true: bare `exit` propagates `wait %1`'s 128+SIGKILL. Measured against GNU bash 5.3.20 with the identical command sequence: script rc 137; rubash: 137. The product agreed with GNU; the expectation did not. Fix, with every GNU expectation from the original pins preserved: counts are scoped to the pin's own job (pipeline stages by pgrp == job leader parsed from the spawn notice, the unrecorded child by ppid == job leader), `finish()` ends the script with an explicit `exit 0`, and PtySession kills+waits its child on Drop so a panicked pin cannot leak its session. Cluster-run after the repair, product still unfixed: both STOP pins and the TERM pin pass; the plain-pid pin fails only on the #2626 survivor assert.
…age (Refs #2626) GNU runs a pipeline's stages as its own direct children: $! IS the last stage's pid, and jobs.c's waitchld (bash-5.3 jobs.c:4057) reaps per process — a job completes only when ALL its processes have completed, and nothing ever signals the siblings. Measured on the GNU 5.3.20 oracle: `sleep 51 | sleep 52 &; kill -TERM $!` leaves sleep 51 running. rubash executes a background body in a wrapper process ($! names the wrapper) whose pipeline stages are armed with PR_SET_PDEATHSIG/SIGKILL (the rubash#737 child-cleanup design), so ANY wrapper death — including an ordinary catchable SIGTERM addressed to $! — cascaded into every stage. Master and this branch both killed sleep 51 within 0.5s (strace: the session's only kill syscall is the builtin's kill(wrapper, SIGTERM); the stages died by the kernel's parent-death signal). Fix by mechanism, keeping the #737 contract (issue866 W1 pin stays green): while a wrapper process supervises a foreground pipeline, it must be transparent for individually addressed catchable signals. At role-arming time — the one single-threaded moment with entry dispositions untouched — the wrapper installs a minimal handler (async-signal-safe self-pipe write) for the relay signal set and saves each signal's entry disposition. The Unix concurrent pipeline path publishes its LAST stage's pid for exactly the span of its wait (WrapperRelayTargetGuard, inert in every non-wrapper process). A relay thread then, per delivery: forwards to the published last stage when the relay still owns the disposition; restores the saved entry disposition and re-raises when no pipeline is in flight (die-by-signal, SIG_IGN-swallow, and entry-handler semantics reproduced); and drops the copy when the disposition has moved to the engine's handler, which records deliveries itself and chains to ours — re-raising there looped one delivery into ~200 trap firings (measured). Trap priority is preserved: a body that traps a relayed signal gets the engine handler at its next reconcile, and the relay steps aside. SIGKILL/SIGSTOP/SIGCONT are uncatchable or kernel-handled and stay out of the set. Residuals, deliberately not papered over: a wrapper that dies by an UNcatchable signal (SIGKILL, crash) while supervising a pipeline still cascades via PDEATHSIG where GNU would orphan the surviving stages — flipping that is the #737/W1 contract decision, not this fix. Sequential (shell-stage) pipelines are not relay-covered; no last-stage pid exists to publish mid-list. Cluster-run: issue2624 pins 4/4 (plain_pid pin is the #2626 regression pin), issue2381 7/7, issue2398 2/2, issue866 4/4, lib kill tests 22/22; non-interactive repro now matches the GNU matrix exactly (last stage dead, sibling alive, jobs shows the job still Running).
e53d205 to
bafc83a
Compare
W24 repair round — all three reds clearedBranch rebased onto master a89e560 (#2623 merged 2026-11-02T14:23Z); the cherry-picked #2622 primitive dropped out of the rebase as previously-applied. New head bafc83a (force-with-lease, fresh remote sha). Full evidence: (1) STOP-pin timeouts — harness defect, product innocent
(2) #2626 — fixed on this branch (bafc83a), PDEATHSIG keptMechanism: Fix: while supervising a foreground pipeline, the wrapper is transparent for individually addressed catchable signals — entry dispositions saved + a self-pipe relay handler installed at role-arming time; the Unix concurrent pipeline path publishes its last stage pid for the span of its wait ( Residuals flagged for captain ruling: (R1) wrapper death by an uncatchable signal/crash still cascades via PDEATHSIG where GNU orphans survivors — measured GNU (3) Verification (cluster-run, final head)issue2624 4/4 · issue2622 2/2 · issue2381 7/7 · issue2398 2/2 · issue866 4/4 · lib kill tests 22/22 · regression 222p/6f — exact baseline set. Two earlier regression runs overlapped each other and were discarded as polluted (186p/42f, 143p/85f); the cited run was solo and scrubbed. Non-interactive #2626 repro now matches the GNU matrix exactly (last stage dead, sibling alive, |
libc::pipe2 is glibc/musl-only — the wrapper relay's self-pipe broke the darwin CI jobs (E0425). Mirror fd/unix.rs create_capture_pipe: pipe2(O_CLOEXEC) on Linux, pipe + FD_CLOEXEC fcntl elsewhere. Captain fix on the W24 repair branch; host cargo check --lib clean, darwin verification is CI's macOS runner (no macOS SDK cc locally).
WIP:
kill %jobspechalf-kills pipelines — it signals onlypids.last()instead of the job's process group.Refs #2624
GNU law
builtins/kill.defjobspec arm:pid = IS_JOBCONTROL (job) ? j->pgrp : j->pipe->pid, thenkill_pid (pid, sig, 1).jobs.c:3961-4020 kill_pidgroup arm: own-pgrp job →killpg (jobs[job]->pgrp, sig); stopped job + TERM/HUP → follow-upkillpg (…, SIGCONT); stopped job + SIGCONT →set_job_running(bg emulation). Shared-group job (pgrp == shell_pgrp) → per-member pipeline walk (already implemented in rubash, kill builtin: signaling a dead-but-unwaited child/job reports ESRCH where GNU succeeds #2381).kill_pid (pid, sig, pid < -1)— single-process delivery, unchanged.Plan
src/executor/limit_builtins.rs: jobspec operands resolving to a job-control job (own pgrp) take a killpg arm via the shared primitive below; per-membernote_kill_deliverybookkeeping retained.c07a82d9verbatim (kill::send_signal_to_process_group) instead of inventing a second killpg wrapper; whichever of WIP: fix(jobs): fg/bg resume via killpg to the job's pgrp (#2622) #2623/[bug][jobs] kill %jobspec 只信号单个 pid(pids.last)而非 killpg 组投递:kill -TERM %1 半杀流水线 #2624 lands second rebases it away as an empty commit.tests/issue2624_*(PTY harness shape from [bug][jobs] fg/bg 的 SIGCONT 逐 pid 发送而非 killpg 组投递:leader 自行 fork 的多进程作业 ^Z 后 fg 永久挂死 #2622's pins):kill -TERM %1kills all pipeline stages,-STOP/-CONTgroup faces, plain-pid kill stays single-process.Cluster delivery: code + pins only, captain verifies.