Skip to content

管道 stage 自身重定向不被应用(cat 3<seed <&3 | wc -c 输出 0) #2255

Closed

Description

@caomengxuan666

分歧(#2235 簇残留格,fix-fd-next-2234-2235 REPORT「Residual cell」;同族独立面)

管道 stage 自身的重定向不被应用:

cat 3<seed <&3 | wc -c    # GNU: 10(seed 字节数);rubash: 0

机制:pipeline stage 运行器(execute_pipeline_stage_inner 与 pipeline_exec.rs/pipeline_stages.rs 的 stage 组合)从不调用 apply_external_redirects/spawn_external_process——stage 的 fd 0 由捕获输入通道组合,其自带重定向列表无人执行。#2235 已修简单外部命令面(PR #2253),本面是管道 stage 的平行缺口,须让 stage 组合走与简单命令相同的重定向应用路径(含 #2235 的 own-list dup 解析)。

验收:上例与 GNU 一致 + 管道 stage 带编号输入/输出重定向的矩阵格(REPORT probes 电池 2/3 的 e8/f6a/f6b 格)全平 + issue2195/2196/2235 钉不回退。

Activity

  1. added this to the 1.5.0 milestone on Oct 30, 2026
  2. added
    bug
    on Oct 30, 2026
  3. added
    gnu-baseline
    P2-medium
    area:fd
    on Oct 30, 2026
  4. caomengxuan666 commented on Oct 30, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合并:PR #2262(合并树 CI 全绿;主会话在 #2253+#2262 复合树上实跑 7 枚钉全绿——含必须两单同在的 e8/f6b 与 procsub 钉)。

    定性:管道 stage 自带重定向时,stage runner 没走 spawn 的投递路径——fd-0 的 dup/close 胜者不被 stage 侧承认(#2235 电池的 e8/f6a/f6b 格)。

    修复:stage runner 改走从 spawn 抽出的共享 apply_external_fd_delivery 助手(不许 stage 侧平行实现),fd-0 dup/close 胜者就此被承认。与 #2253 的复合关系已在钉文件头逐格标注并双向验证。

    REPORT 残面处置:①fd-0 close 在 inline 臂不可表达——属观察记录、非已证分歧,不立案;②inline-stage 编号输出绑定的创建副作用——同上,先记入全仓审计线备查,两者均待审计批次以探针定性后再决定是否立案。

  5. caomengxuan666 commented on Oct 30, 2026

    @caomengxuan666
    MemberAuthor

    重开本单:PR #2262 的关单验证被环境掩盖,本单的核心主张只兑现了一部分。裁定全文在 ~/workspace/adjudicate-2255-stage-reds/REPORT.md,要点:

    两枚红钉的裁定(主会话批复跑坐实)

    issue2255_pipeline_stage_redirects 在当前 master 确定性 5/7,红的是 f6a(sh -c 'cat <&3' 3<seed.txt | wc -c 应得 10、实得 0)与编号输出(3>o.txt 应把 o 写进文件、实得 o 漏进下游管道)。两钉经 oracle 逐字节核对是对的;产品自钉子写就的那一提交(afc1845a)起就红——不是任何后续合并的回归。

    关单时记录的 7/7 是真实观察、但只在启动器继承了额外 fd 的布局下成立:stage 的 stdout 管道恰好不落在 3 号槽,守卫不误伤。干净 fd 布局下管道确定性落在 3 号槽,红就出现。教训:fd 敏感钉的绿依启动器 fd 布局而定,批验证必须在洗净 fd 的环境下做并记录。

    根因与已备修复

    pin_ambient_fds_in_child(#1626 引入的守卫)无法区分 exec-error 管道与 stage stdio 管道在目标槽上的残留:stage 子进程里 std 先把 stdout 管道 dup2 到 1、原号(此处 3)留到 exec 才关,fstat 分不出它与错误通道,于是目标槽停着匿名管道时 pin 被静默丢弃——即 GNU 给该 stage 的重定向被牺牲。简单命令面靠布局运气(投递自己的 open 常落在 3、源==目标短路)逃过。

    修复已备:草稿 PR #2284——守卫改为以 fstat 的 (dev, inode) 身份与 0/1/2 比对来精确识别 stdio 残留,错误通道永不匹配、保护不减。主会话按标准收割流程处理。

    本单剩余范围(#2284 落地后仍开着的理由)

    ≥3 级管道的 stage-0 编号输入仍丢绑定(裁定 §8,独立面):

    sh -c 'cat <&3' 3<seed.txt | cat | wc -c   → 子进程根本没有 fd 3(dash 报 3: Bad file descriptor),实得 0;GNU 得 10
    

    与两钉的 pin-守卫面不同:这个组合里 stage 0 走的是另一条 spawner 路,绑定从未投递。对照边界:2 级 stage-0 由 #2284 修;3 级的中间 stage 编号绑定今天就是好的。归宿:定位 ≥3 级组合中 stage 0 的实际 spawner 面并补投递,复现形如上,期望取 GNU。

    #2284 合并后本单保持 open,直到此面落地。

  6. caomengxuan666 commented on Oct 30, 2026

    @caomengxuan666
    MemberAuthor

    Closing — the §8 residual (≥3-stage stage-0 bindings) is fixed by PR #2289 (merge commit c537d12), completing the issue. The earlier faces landed via PR #2262 and PR #2284; this comment covers the final segment and the two extra mechanisms it exposed.

    §8 input face. In a ≥3-stage pipeline, stage 0's numbered input binding was lost entirely. Root cause (strace-proven): the shell-writer pipeline admission never inspects the ordered redirects list; it spawned the consumers on pre-created pipes before running the producer, so a foreign pipe end parked exactly on the binding's slot and the pin_ambient_fds_in_child guard (#1626/#2284) could not distinguish it from std's exec-error channel — the delivery opened the binding, the dup2 never ran. Fix: the shell-writer path now declines an external producer carrying a list-only redirect (fd > 2 or {var}), so the sequential loop spawns stage 0 in a clean fd layout and the shared delivery lands. The decline exempts pure stdio dups (the writer path delivers those correctly at 2 stages).

    Second mechanism found during the fix — output wipe. Stage numbered output was also broken, differently: the child's bytes landed in the target file and were then truncated to 0 after the stage exited, because route_pipeline_stage_streams re-runs the ordered output walk post-stage and its create/truncate validation open (the #1868 dropped-File model) fired for numbered targets the element had already written directly. On master this wiped mid- and last-stage numbered output too. Fix: OutputFdState::resolve_only_numbered — in routing mode the walk still resolves the whole list but records fd > 2 targets with no filesystem open. GNU opens once per redirection, in the fork (execute_cmd.c:2620, redir.c:237).

    Verification. Collector batch under a scrubbed fd environment on the composed tree: tests/issue2255_pipeline_stage_redirects.rs 14/14 (the original 7 + §8 three/four-stage input + stage-0 output + middle/last-stage output + dup-chain pins); controls issue1963 6/6, issue2235 11/11, issue2250 5/5, issue2256 25/25; streaming spot checks (yes | head -3, yes | head -1 | wc -l) intact. CI green on the branch head (09937fd) and on the composed head (4c3a0e8). A 19-case GNU battery matched 17; the 2 remaining diffs are byte-identical on master (pre-existing) and are filed as #2294 and #2295; the sequential-spawner stdio-dup gap is filed as #2293; the consumer-chain pipe-end leak observation went to the audit ledger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-mediumarea:fdbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions