Skip to content

[bug] coproc construct-level fd redirect (3>file) is dropped at the spawn boundary: body writes fail 'Bad file descriptor' #2200

Closed

Description

@caomengxuan666

[bug] A construct-level fd redirect on a coproc is not established for the respawned child: the file is created but the body's write to that fd fails with "Bad file descriptor" and nothing is delivered. Body-internal redirects work; the construct-level redirect is dropped at the coproc spawn boundary.

Repro (verified 2026-10-30 on master acf8fef, GNU bash 5.3.20 as oracle):

rm -f fd3out.txt
coproc CP { echo hello-fd3 >&3; echo hello-stdout; } 3>fd3out.txt
sleep 1
cat fd3out.txt

GNU 5.3.20: fd3out.txt contains hello-fd3, no diagnostics.
rubash: stderr 3: Bad file descriptor, fd3out.txt is empty.

Regression seed: the script above; assert the file content equals hello-fd3 and stderr is empty. Sibling shapes worth pinning in the same pass: construct-level redirects on the other respawn sites (async &, procsub consumer/producer) and a numbered-fd input redirect on coproc.

Context: found by the #2058 respawn-transport census (its REPORT §3 side note) and re-verified by the main session against the oracle. Same spawn-boundary fd-state family as #2195 (procsub consumer spawn-time fd state) — adjudicate together when dispatching; the fd governance fixes in #2170/#2171 are the neighboring precedents.

Activity

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

    @caomengxuan666
    MemberAuthor

    已随 PR #2232 合入关闭(第二轮 CI run 41074215620 全绿)。

    修法:apply_coproc_redirects 收集编号 fd 绑定(文件入/出/追加/读写、关闭、dup 含 3>&1 这类管道源 dup;词 dup 按 GNU 报 ambiguous redirect),并把绑定传进 coproc 子进程的两条路线(respawn 走 env、direct 走 pre-exec pin);dup 只在遍历完成后创建,退让路径不泄漏任何绑定。钉 4 枚(issue2200 文件),基线红、修复绿,探针与 GNU 逐字节一致(含 coproc 输入与 3>&1 管道 dup)。

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

Metadata

Metadata

Labels

area:fdbuggnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions