Repository navigation
WIP: fix(coproc): #1882 stderr seam — direct fd-2 endpoint for the child + startup SIGPIPE policy - #1884
Merged
Conversation
…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
force-pushed
the
fix/coproc-stderr-1882
branch
from
October 27, 2026 16:34
b6a33de to
482e7c4
Compare
caomengxuan666
marked this pull request as ready for review
October 27, 2026 16:36
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.
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 脚本文件对照)
stderr 全量送达、fd2→另一 coproc stdin、exec 2>file/2>&1 后父死送达)。
tests/issue1882_coproc_stderr_seam_regressions.rs10 条:修复树 10/10;pristine 上 6 条面钉红、4 条守卫钉双树皆绿。
lib 787/1/1(唯一失败 = 基线
ownership_unary_operators_check_existing_file)。-D warnings(lib+bins+新钉)干净;改动文件rustfmt 干净、CR=0。
[bug] 管道中前置命令触发 SIGPIPE 会让 niu 整个进程以 141 退出 #440 io 错误面);钉为跨平台文件,Windows 行为请 CI 复核。
簇内全量证据:
~/workspace/issue-clearance/clusters/coproc-stderr/REPORT.md(本地工作区,不入仓)。