Skip to content

fix(executor): drain signals while waiting for foreground children - #3367

Merged
caomengxuan666 merged 3 commits into
unixwin:masterfrom
Uarz:fix/issue-3284
Nov 12, 2026
Merged

caomengxuan666 merged 3 commits into
unixwin:masterfrom
Uarz:fix/issue-3284

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Refs #3284

What was fixed

Foreground waits blocked until the child ended, so a terminating signal was only consumed at the command-end boundary instead of mid-wait. Waits are now sliced (10 ms try_wait) with mailbox draining (observe_signals_while_blocked), so the signal is consumed while waiting and the shell dies by the signal (GNU jobs.c:3064 wait_for + quit.h:53 CHECK_TERMSIG, sig.c:650 kill_shell).

What was NOT fixed (this PR is partial — hence Refs, not Fixes)

The command-substitution face is still red: x=$(/usr/bin/sleep 5) with TERM to $$ dies at 5.02 s instead of promptly. The comsub body runs in an in-process clone, and the flat-layer guard (subshell_depth > 0 && shell_pid == process::id(), #2236) stops the clone's wait from draining. Opening the guard directly would break the death direction (the clone would record the death and the parent would survive with 143). The correct lane is two steps — drain for the comsub clone only (new flag, not the shared guard) plus passing termsig_death_pending back to the parent — and is left as a residual for a follow-up.

What was deleted

Nothing. No files, features, or tests were removed.

Verification (all run, per-item counts)

  • Regression pin tests/issue3284_engine_wait_termsig_regressions.rs: 8 passed / 1 failed (9 tests). Fail-first on the unpatched tree: 5 failed (term-ext, hup-ext, term-pipe, term-comsub, term-merged — all ~5.02–5.20 s), 3 passed. After the fix only term-comsub fails (5.02 s).
  • Adjacent signal families: issue2346_termsig_death_regressions 11/11, signal_trap_coverage_regressions 7/7, issue1035_1036_signal_table_regressions 9/9, issue2236_nested_signal_death_regressions 9/9, issue2353_ancestor_lane_termsig_regressions 13/13.
  • issue1990_1991_signal_job_regressions: 3 passed / 3 failed — reproduced identically on the unpatched tree (pre-existing, unrelated).
  • cargo build -j 2 clean, cargo fmt --check clean. src/lexer/continuation.rs untouched.

Owed

  1. comsub timing residual (above).
  2. Exec simulation face (run_external_exec_with_stdio) has no drain.
  3. Interactive job-control waits not drained, unprobed.
  4. read builtin blocked-read face (GNU 0.05 s vs rubash ~2.01 s) — a different face, unprobed.
  5. Procsub face unprobed.

Foreground waits blocked until the child ended, so a terminating signal was only consumed at the command-end boundary. Waits are now sliced (10 ms try_wait) with mailbox draining, so the signal is consumed mid-wait and the shell dies by the signal.

Refs unixwin#3284

Regression pin: tests/issue3284_engine_wait_termsig_regressions.rs (9 tests; fail-first 5 failed on the unpatched tree, 8 pass after, 1 still fails: term-comsub dies at 5.02 s instead of promptly). Adjacent signal families green. The comsub face needs a two-step lane (drain for the comsub clone + pass termsig_death_pending back to the parent) and is left as a residual.

Owed: comsub timing residual; exec simulation face has no drain; interactive job-control waits not drained; read builtin blocked-read face; procsub face unprobed; issue1990_1991 3 failures are pre-existing.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复 labels Nov 11, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 11, 2026
@caomengxuan666 caomengxuan666 added the area:jobs jobs, signals, process ownership, coproc label Nov 11, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge; noted as partial (Refs #3284, comsub face left as a residual for follow-up). CI at intake: all checks green. No action needed unless the review asks for changes.

@caomengxuan666

Copy link
Copy Markdown
Member

Captain review: PASS, with mandatory pre-merge conditions below. Full dossier: ~/workspace/review-3367/CAPTAIN-VERIFY.md in the captain's workspace (§4 bilateral runs, §5 race adjudication, §6 residual delimitation, §7 conditions).

What the review verified (Simular box, plain cargo route, per-stem verdicts):

  • Difference audit: exactly the 3 declared files; src/lexer/continuation.rs untouched; no closing-keyword adjacency anywhere in title/body (Refs 引擎等待面:前台命令执行期终止信号只在命令结束边界被消费,GNU 在等待中即信号死(niu #988 时序残差归宿) #3284 only).
  • GNU mechanism check, source-first: the 10 ms slice + drain + kill-child-before-unwind shape matches wait_for's in-loop CHECK_TERMSIG polling (jobs.c:3064), termsig_handler's trap-then-die order (sig.c:590), and run_pending_traps deferral (execute_cmd.c:643). Mechanism-level repair, not case patching.
  • Pin issue3284_engine_wait_termsig_regressions, bilateral: base (8f904d3f, pin topped up) 2 passed / 7 failed → head 7 passed / 2 failed, stable across two full-stem runs. Fail-first is stronger than declared (you reported base 5 red; pipe-first is red on base unix too, by mechanism). Adjacent stems all green (2346 11/11, signal_trap 7/7, 1035_1036 9/9, 2236 9/9, 2353 13/13); lib failure name-sets empty on both sides; fmt / marker-lint / whole-tree UTF-8 hygiene / RUSTFLAGS="-D warnings" all rc=0 with the warnings flag proven loaded.
  • The 2 head reds are both adjudicated, neither introduced by this PR:
    • term-comsub: the declared residual — delimited and filed as [bug] termsig death still delayed on comsub, blocking-read and simulated-exec waits (residual of #3284) #3401 (face 1).
    • term-exec: a pin-construction race, proven by probes — both binaries truly execve and die by TERM at ~0.33 s in pipe / devnull / regular-file / pty shapes when run solo (the cell passes solo in 0.53 s); under full-stem parallel load the fixed +0.3 s delivery can land before the image replacement and the recorded death is erased by the execve. Not a product defect.
  • One CI note: the "Rust tests" job runs nextest --lib plus a fixed stem list that does not include the new issue3284 stem, so CI green carries no evidence for the pin — the box bilateral runs above are the pin's evidence.

Residual delimitation (dossier §6) is now filed as #3401, assigned to you: face 1 comsub clone drain, face 2 blocking read wait (probe-live on this head: no death within an 8 s cap vs GNU 0.31 s), face 3 simulated-exec wait (code-sited in src/builtins/exec.rs), plus note 5 (out-of-wait delivery absorption) as an observation. The procsub face was probed and adjudicated no divergence (GNU also defers to ~5.0 s there) — that row needs no work.

Pre-merge conditions (all required):

  1. One review-response commit from you: gate the issue3284_term_during_comsub_wait_dies_promptly cell with #[ignore] and a comment pointing at [bug] termsig death still delayed on comsub, blocking-read and simulated-exec waits (residual of #3284) #3401, so master never carries a live red cell; the [bug] termsig death still delayed on comsub, blocking-read and simulated-exec waits (residual of #3284) #3401 repair un-gates it. In the same commit, please also harden the term-exec cell's delivery timing if convenient (sync delivery with an observable child state, or delay delivery to ~1.0 s) — if not, the merge round will apply the adjudicated protocol (full-stem red in the exit-code-0 shape + solo green = race, merge proceeds with a note).
  2. An update-branch is required before merge: the interval since the merge-base touches src/executor/external_inner.rs. Merge order relative to PR fix(executor): route pipeline stage stderr through the fd table in command substitution #3364 (also touches pipeline_exec.rs) is the captain's call; the later one rebases first.
  3. Merge-round re-runs on the final head: full pin stem ×2 plus a solo term-exec run, read per the protocol in condition 1.

This PR must not close #3284. Once it merges, the captain will close #3284 manually with a pointer to #3401 and to the dossier.

@caomengxuan666

Copy link
Copy Markdown
Member

2026-11-12 用户令:不等作者门控提交,队长接手。复核 §7 的 comsub 格 #[ignore] 门控提交由队长车道追加,之后按 §7 协议走合入轮;合入后队长手动关 #3284 并留 #3401 指针。作者原提交全部保留。

caomengxuan666 and others added 2 commits November 12, 2026 01:00
Captain takeover (user order 2026-11-12): apply PR unixwin#3367 review
condition 1. The term-comsub cell stays red because the comsub clone
layer never consumes the termsig mailbox (residual unixwin#3401; captain
review dossier section 6, face 1), so gate it with #[ignore] to keep
a live red cell off master; the gate comes off with the unixwin#3401 fix.
No product code and no other cell touched.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 01:51
@caomengxuan666
caomengxuan666 merged commit 82244ad into unixwin:master Nov 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:jobs jobs, signals, process ownership, coproc bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants