Skip to content

WIP: fix(coproc): #1882 stderr seam — direct fd-2 endpoint for the child + startup SIGPIPE policy - #1884

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/coproc-stderr-1882
Oct 27, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/coproc-stderr-1882

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1882

接缝(w3-rem-core 成对定谳,两面同修)

面 1 — 转发链随父死亡。 coproc 子 stderr 走管道 + 父进程内转发线程
(forward_coproc_stderr);父 shell 退出时线程与读端同死,子进程迟到
诊断整条丢失。GNU 的 fork 子持有 shell 当前 fd 2 的真实描述符
(execute_cmd.c:2525 make_child(..., FORK_ASYNC);execute_in_subshell
只重绑 stdin/stdout 两管),父死毫无影响。

面 2 — 子进程 SIGPIPE 停在 SIG_IGN。 coproc 子在 Executor::new 里
因 Windows TERM 邮箱豁免跳过 register_signal_mailbox_async,在 Unix 上
连带跳过了 capture_entry_and_policy()——#1333 的 SIGPIPE→SIG_DFL 复位
的唯一启动触发(strace 定谳:子全程零条 rt_sigaction set)。于是死管道
写返回 EPIPE、经 report_io_error_routed 自印 Broken pipe 伪诊断并
继续执行 body。GNU fork 子经 reset_signal_handlers(execute_cmd.c:1670)
回默认处置、写点静默死;#440 的「报告并继续」口径只管壳内命令。

面 1 若单独改直继承,面 2 的伪诊断即暴露并使 #387 在册钉转红——故同 PR。

修法

  • coproc_stderr_plan()(compound_exec.rs):句柄型端点(inherit /
    Stdout dup / File dup——共享偏移,比旧逐块 append 更贴 GNU / 另一
    coproc stdin 管 dup / 已关闭→null)在 spawn 时直给子进程,沿
    BackgroundStdio 先例;仅 ProcessSubstitution 载体端点(及 dup 失败
    回退)保留管道+转发。coproc 自有 2>file 等覆盖语义不变(p12 钉守);
    dup 形重定向仍是 held PR fix(executor): coproc honors dup output redirects like >&2 (rubash#1644, #1655) #1695 的面,未触碰。
  • capture_entry_policy_without_mailbox()(kill.rs,Unix 上即
    capture_entry_and_policy、余平台 no-op);init.rs 的 coproc 子分支
    保持 owns_signal_mailbox = false 的同时调用它。

验证(本地 Linux,GNU 5.3.20 脚本文件对照)

  • 簇内探针 p1–p7/p12–p18 与 GNU 逐条字节同形(含迟到 3000 行
    stderr 全量送达、fd2→另一 coproc stdin、exec 2>file/2>&1 后父死送达)。
  • 新钉 tests/issue1882_coproc_stderr_seam_regressions.rs 10 条:
    修复树 10/10;pristine 上 6 条面钉红、4 条守卫钉双树皆绿。
  • coproc: body stdout leaks one blank line to the real stdout (GNU discards it) #387 钉 3/3 不红;coproc 家族 18 个测试二进制 102 钉全绿;
    lib 787/1/1(唯一失败 = 基线 ownership_unary_operators_check_existing_file)。
  • diffcorpus 306/306;-D warnings(lib+bins+新钉)干净;改动文件
    rustfmt 干净、CR=0。
  • Windows 面:面 2 捕获是 Unix 处置面(Windows 无 SIGPIPE,EPIPE 仍走
    [bug] 管道中前置命令触发 SIGPIPE 会让 niu 整个进程以 141 退出 #440 io 错误面);钉为跨平台文件,Windows 行为请 CI 复核。

簇内全量证据:~/workspace/issue-clearance/clusters/coproc-stderr/REPORT.md
(本地工作区,不入仓)。

…cy (#1882)

Two paired seams in coproc spawn (w3-rem-core paired adjudication):

1. The child's stderr travelled a pipe plus a forwarding thread in the
   parent; when the parent shell exited, the thread died with it and the
   child's late diagnostics were lost wholesale. GNU's forked child
   holds the shell's current fd 2 as a real descriptor —
   execute_cmd.c:2525 make_child(FORK_ASYNC); execute_in_subshell binds
   only the two coproc pipes (stdin/stdout) — so its writes land
   whenever they happen. coproc_stderr_plan() now hands handle-backed
   endpoints to the child directly (inherit / dup of the process std
   handle / dup of the bound file or coproc-pipe handle, sharing the
   file offset), mirroring the BackgroundStdio precedent. Only the
   process-substitution carrier endpoint (and dup-failure fallbacks)
   keep the forwarding transport.

2. The coproc child skipped Executor::new's signal registration for its
   Windows TERM-mailbox exemption, which on Unix also skipped
   capture_entry_and_policy() — the only startup trigger of the #1333
   SIGPIPE->SIG_DFL reset. The exec image's runtime SIG_IGN survived,
   so a write to the dead coproc pipe returned EPIPE and was reported
   via report_io_error_routed as a `Broken pipe` self-diagnostic while
   the body kept executing. GNU's fork child restores default signal
   dispositions (execute_cmd.c:1670 reset_signal_handlers) and dies
   silently on SIGPIPE mid-write; the #440 report-and-continue model
   governs in-shell commands, not fork-model children. The child now
   runs capture_entry_policy_without_mailbox() (the TERM-mailbox
   exemption itself is unchanged).

Regression pins: tests/issue1882_coproc_stderr_seam_regressions.rs
(10 pins, GNU bash 5.3.20 script-file expectations; the six face pins
fail on pristine master, the four guard pins pass on both trees).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 27, 2026 16:36
@caomengxuan666
caomengxuan666 merged commit ab47141 into master Oct 27, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/coproc-stderr-1882 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.

[coproc] 子进程 stderr 经管道转发,父退出时迟到诊断整条丢失(与 respawn EPIPE 伪诊断成对接缝)

1 participant