Skip to content

fd: redirect failure mid-list does not undo partial binds (GNU undo_partial_redirects) #3733

Closed

Description

@caomengxuan666

Mechanism (proven by #3706)

#3706 isolated the hazard and #3723 fixes it for group redirects: a scope save that only Rc-clones the userspace FdEntry, followed by a bind that retires the displaced kernel descriptor (retire_read_arm/retire_write_arm, #3213), followed by a restore that re-inserts the retired entry — the next spawn's pin pass then dup2's whatever recycled that kernel number onto the fd. GNU's undo save IS a kernel dup (fcntl (fd, F_DUPFD, SHELL_FD_BASE), redir.c:965/1082/1144; compound groups run do_redirections (..., RX_ACTIVE|RX_UNDOABLE), execute_cmd.c:854). Fix direction: snapshot via a kernel dup the way #3723 does (FdTable::saved_entry / FdEntry::dup_file_endpoints), never a bare clone.

Destination

Fix lane, same wave as #3723. The lane must first reproduce the divergence against GNU bash 5.3 with a fail-first regression pin (named with this issue), then fix by mechanism. Dispatch only after a fresh open-PR guard scan on the touched files.

Site

When a redirect list fails part-way, the numbered binders do not undo the binds already applied; GNU calls undo_partial_redirects (execute_cmd.c:855) so a failed redirect list leaves the fd table exactly as before. The #3723 fix's saved dups close cleanly via Drop (no leak), but the partial-bind restore itself is missing — a separate face from #3706, same area. Repro: a redirect list whose later element fails (e.g. N</nonexistent after an earlier successful bind in the same list) must leave the earlier fd untouched; GNU does, rubash keeps the partial bind.

Activity

  1. added this to the 1.5.1 milestone on Nov 15, 2026
  2. added
    bug
    on Nov 15, 2026
  3. added
    gnu-baseline
    area:fd
    on Nov 15, 2026
  4. caomengxuan666 commented on Nov 17, 2026

    @caomengxuan666
    MemberAuthor

    【WIN-AGENT-AUDIT】续作完成 — 建议 PASS(待队长终审)

    PR #3853(head 2dea6fe73,基底 3d8c9ff8f)。

    根因:open_compound_numbered_input_redirects(command_input_scope.rs)在 _in 出错时丢弃已累积的 saved 快照——输出侧 wrapper 本就 unwind,输入侧漏了。GNU 依据:undo_partial_redirects(execute_cmd.c:855)+ add_undo_redirect 内核 dup 保存(redir.c:1326)。同法补齐 same-exe script face 的 bind_script_numbered_inputs_and_fd_vars(trap_exec.rs)Err 臂。

    证据:master 上可复现({ :; } 8<f9 9<f8 7</non/nope 后 fd8/fd9 互换,GNU 保持原绑定);修复后 49-cell cfg(unix) 钉全绿,base 上 28 红(fail-first 成立);WSL 原生 lib 双边 1274/0 差集空;GNU 5.3.20 脚本对照一致。

    相邻残差(另列,未扩 scope):输入/输出两遍绑定 vs GNU 单次有序 walk 的副作用顺序差(8>newfile 7</non/nope 中文件创建与否),fd 状态两侧均正确。

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