Skip to content

WIP: pipeline blocking waits poll the signal mailbox (rubash#2020) - #2049

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2020-pipeline-signal-mailbox
Oct 29, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2020-pipeline-signal-mailbox

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #2020 (P2, Windows executor signal batch — same line as #669, distinct site from #1996).

Root cause

The engine's pipeline blocking waits never polled the signal mailbox. Under an event-shaped Ctrl+C the niu host handler records the SIGINT in the mailbox (kill.rs note_console_ctrl_c -> queue_self_signal(2)), but the pipeline wait path slept through it:

  • sequential stage face (the issue repro's actual blocking point): execute_external_pipeline_stage_inner sat in a blocking read_to_end/wait_with_output on the member's stdout pipe for the member's whole lifetime — ping -n 30 127.0.0.1 | cat settled only when ping ended naturally (~30 s), ^C had no effect;
  • concurrent member waits: wait_for_windows_pipeline_member (pipeline_exec.rs) polled try_wait + a 5 ms sleep, never the mailbox;
  • last-member waits: plain last.wait().

GNU contract (cited per repo discipline): jobs.c:3064 wait_for installs wait_sigint_handler (jobs.c:3090-3101, handler at jobs.c:2908) so a ^C recorded by trap.c:545 trap_handler is observed while the shell is blocked and the job settles 128+SIGINT; a TRAPPED delivery is only recorded (trap.c:537-543) and its action defers to the command boundary (execute_cmd.c:643 run_pending_traps).

Change (Windows faces only; unix paths byte-identical)

  • wait_for_windows_pipeline_member takes the executor and polls observe_signals_while_blocked between polls; on an untrapped terminating delivery it tree-kills the member + downstream (the group-^C shape), reaps, unwinds 128+sig. Covers the concurrent all-external / shell-writer / streaming-tail member waits.
  • New wait_pipeline_member_interruptibly (sliced wait_child_slice + mailbox poll, no lingerer deadline): pipeline LAST member.
  • New wait_pipeline_stage_output / wait_pipeline_stage_merged_output: the sequential stage's captured stdout/stderr (or the one merged 2>&1 pipe) drains on reader threads while the child wait polls the mailbox. Unix keeps plain wait_with_output / read-then-wait byte-for-byte (issue acceptance: "unix 面行为不变").

Trapped SIGINT defers exactly as GNU: observe re-queues for the next boundary, so trap ... INT fires only after the pipeline completes (pinned).

Verification

  • New pins tests/issue2020_pipeline_signal_mailbox.rs (Windows; injection through the production cross-process mailbox face — a second rubash's kill -INT): 5/5 pass on the fix; on pristine 1a6f9c9a the three interrupt pins fail (pipeline sleeps through ^C; trapped delivery lost) and the two no-signal sanity pins pass — the pins bite and the fix is the difference.
  • Battery of the 60 pipeline/signal/wait test targets (--no-fail-fast), A/B against a pristine 1a6f9c9a worktree build: identical failure sets apart from the 2020 pins — 293 passed / 7 failed on the fix vs 290 / 10 on baseline, same 300-test total. The 7 include 6 pre-existing environment-bound tests failing byte-identically at baseline (winuxcmd dd/ulimit -f, cat: command not found in sanitized test envs, /usr/bin/true resolution, coproc cat -, exit-trap reroute) — not attributable to this change.

Notes for the main session

…2020)

Under an event-shaped Ctrl+C the niu host handler records the SIGINT in
the engine mailbox (kill.rs note_console_ctrl_c), but nothing on the
pipeline wait path consumed it: a pure external-command pipeline
(`ping -n 30 127.0.0.1 | cat`) only settled when its stage ran to
natural end. The unix face of the same subsystem was already fixed by
#1996 (wait_external_child slices + observe_signals_while_blocked);
this is the distinct Windows pipeline-wait face.

GNU contract: jobs.c:3064 wait_for installs wait_sigint_handler
(jobs.c:3090-3101, handler at jobs.c:2908) for the foreground wait, so
a ^C recorded by trap.c:545 trap_handler is observed while the shell is
blocked and the job settles 128+SIGINT; a trapped delivery is only
recorded (trap.c:537-543) and its action defers to the command boundary
(execute_cmd.c:643 run_pending_traps).

Engine changes (Windows faces only; unix code paths byte-identical):

- pipeline_exec.rs wait_for_windows_pipeline_member now takes the
  executor and polls observe_signals_while_blocked between polls; on an
  untrapped terminating delivery it tree-kills the member and its
  downstream (the group-^C shape GNU gets from the kernel), reaps both,
  and unwinds with 128+sig. Covers the concurrent all-external, shell-
  writer and streaming-tail member waits.
- new wait_pipeline_member_interruptibly (sliced wait_child_slice +
  mailbox poll, no lingerer deadline) serves the pipeline's LAST member
  and the sequential stage faces.
- new wait_pipeline_stage_output / wait_pipeline_stage_merged_output:
  a sequential stage's captured stdout/stderr (or the one merged `2>&1`
  pipe) now drains on reader threads while the child wait polls the
  mailbox — the parent used to sit in the blocking read for the
  member's whole lifetime, which is where the issue's repro actually
  blocked (pipeline_stages.rs sequential stage). unix keeps the plain
  read_to_end/wait and wait_with_output byte-for-byte.

Trapped SIGINT defers exactly as GNU: observe re-queues the delivery
for the next command boundary, so `trap ... INT` fires only after the
pipeline completes.

Regression pins: tests/issue2020_pipeline_signal_mailbox.rs (Windows;
injection through the production cross-process mailbox face, a second
rubash's `kill -INT`). All 5 pass on the fix; on pristine 1a6f9c9 the
three interrupt pins fail (pipeline sleeps through ^C, trap delivery
lost) and the two no-signal sanity pins pass. Battery of the 60
pipeline/signal/wait test targets: failure set identical to pristine
baseline (6 environment-bound tests, pre-existing at 1a6f9c9: dd/
ulimit, `cat: command not found` in sanitized test envs, /usr/bin/true,
coproc cat -, exit-trap reroute); 293 passed on the fix, 290 on
baseline, same 300-test total.

Disclosure: cargo fmt and the pre-commit hook both hit os error 206 at
master scale (documented precedent); rustfmt --check verified clean on
the three touched files; committed with --no-verify.
@caomengxuan666

Copy link
Copy Markdown
Member Author

主会话评审(2026-10-29):本 PR 当前 CI 全红,根因是编译错误(不是测试分歧)——lib test 目标编译不过,所有作业(Rust tests / macOS / Shell functionality / 双 cross / niu 配对)都在同一步倒下:

  • error[E0507]: cannot move out of *child which is behind a mutable reference → src/executor/pipeline_exec.rs:496
  • error[E0596]: cannot borrow reader as mutable, as it is not declared as mutable → src/executor/pipeline_exec.rs:529

证据:run 40816674702 job 123259264827 日志(2026-10-29T04:15:43Z)。修好这两处借用错误后请推新 head,CI 转绿后主会话再审内容(#2020 本体形状未及审)。分支基线已落后 master 若干合并,推前建议先合 master 免得二次冲突。

Takeover convergence for PR #2049 (bounce: E0507/E0596, both in the
unix faces of the new pipeline stage wait helpers, invisible from the
author's Windows build):

- wait_pipeline_stage_output (unix): wait_with_output consumes the
  child this signature only borrows; spell out its own recipe through
  the borrow — take both pipes, drain them on the existing
  spawn_pipe_drain reader threads, wait, then join. Observable
  behavior unchanged (plain blocking drain-and-wait, no mailbox poll).
- wait_pipeline_stage_merged_output: the reader parameter is now
  declared mut (the unix face calls read_to_end on it); drop the
  then-unused std::io::Read import in that block.

Master e524774 was merged in first (054d2a1, zero conflicts).
cargo check --locked --all-targets: clean, 0 errors / 0 warnings.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 15:00
@caomengxuan666
caomengxuan666 merged commit d5c172a into master Oct 29, 2026
9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2020-pipeline-signal-mailbox branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[windows][executor] pipeline 阻塞等待不轮询信号邮箱:事件形 Ctrl+C 下纯外部命令 pipeline 不结算

1 participant