Repository navigation
fix(executor): dup-save procsub spawn-plan fds before the plan bind retires them (Refs #3732) - #3741
Conversation
…etires them (Refs #3732) The in-process output-procsub consumer runs under the compound's prefix redirects as its spawn plan (with_procsub_spawn_plan, rubash#3491). The plan bind saved the displaced entry with a bare Rc clone and then retired the displaced descriptor on every arm — FdTable::close (Closed), set_fd_input_file (File read / CarrierRead), open_output (File write / TruncatedFile / CarrierWrite / CaptureWrite / StreamWrite) — so the restore re-inserted a retired entry and the next read/write (or the next spawn's pin pass) hit a dead descriptor. GNU's undo save IS a kernel dup (fcntl (fd, F_DUPFD, SHELL_FD_BASE), redir.c:965/1082/1144; SHELL_FD_BASE is 10, redir.c:86; compound groups run do_redirections (..., RX_ACTIVE|RX_UNDOABLE), execute_cmd.c:854). This makes the plan-bind save the same kernel dup: FdTable::saved_entry duplicates every File-backed endpoint (FileFd::duplicate, F_DUPFD_CLOEXEC on unix, non-inheritable duplicate on Windows), applied at the single save point that covers all bind arms. A <> pair's two arms share one Rc; the save preserves that sharing so closing one direction still retires the shared descriptor, as GNU's close(2) closes the whole descriptor. A dup failure fails the consumer run (GNU REDIRECTION_ERROR) before it starts, unwinding the bindings already made; with_procsub_spawn_plan now returns Result<T, ExecuteError> and its single caller surfaces the bind error exactly like the consumer's own error. Note: the three fd_table.rs helpers are the same code as PR #3723 (Refs #3706), which is still an open draft on the same base — #3723 adds them for the group-redirect save sites, this PR for the spawn-plan save site. Whichever merges second drops its copy of the helper hunk; the product hunks do not overlap (#3723 touches command_input_scope.rs / compound_exec.rs / external_finish.rs, this PR touches external_setup.rs / pipeline_exec.rs). Regression pin: tests/issue3732_procsub_spawn_plan_fd_restore.rs (11 cells: File-read fd 8/3, Closed, TruncatedFile, append-File, ReadWrite <>, CarrierRead, CarrierWrite, no-displacement control, external-child /proc face, <>-close sharing guard). UNVERIFIED-BY-CAPTAIN: no build slot was available (Simular box hibernated, X299 unreachable, old server unreachable, local builds forbidden), so the pin's fail-first run and the verification legs are owed; see the PR body. 本 PR 删除了什么:未删除任何内容(纯增量修复;仅将 with_procsub_spawn_plan 的返回由 T 改为 Result<T, ExecuteError>, 唯一调用点同步适配;无删除的功能、文件或公开面)。
ce56c07 to
dbdba55
Compare
|
【WIN-AGENT-AUDIT】 机制核查:
F 点:
腿(按调度指令不重跑,仅记录已有证据与缺口):
未跑/VOID 的腿:
|
|
【WIN-AGENT-AUDIT】PR #3741 第2轮 — 建议:FAIL 机制核查:
腿:
F 点:
续作记录:本轮为验证+定位轮,未动代码。 |
|
【WIN-AGENT-AUDIT】PR #3741 第3轮 — 建议:FAIL(维持第2轮判词,F1 本轮独立复现确认) head 与第2轮 FAIL 判定时完全一致(gh api 复核未动)。本轮在 WSL Linux 侧独立复验(/root/rubash-wsl-t2 @dbdba55e,cargo 1.99.0-linux): 腿:
F 点:
续作记录:本轮为验证轮,未动代码。 |
|
【WIN-AGENT-AUDIT】PR #3741 第4轮 — 续作开工 根因已定位(WSL strace + 临时插桩,探针 target 侧 procsub3741.sh):
处置:merge origin/master 进本支(消化 #3723 的 saved_entry 转换),再全腿复核(WSL Linux 原生钉 + fail-first + lib 双边 + GNU 对照)。若合并后钉仍红,再按残余面单独处理。 |
…te end undelivered on Windows (Refs #3732)
|
【WIN-AGENT-AUDIT】PR #3741 第4轮 — 建议:PASS 机制核查:
腿(逐项数字):
F 点(对第3轮 FAIL 的逐条回应):
续作记录:
未跑/VOID 的腿:无。 |
根因
与 #3706 同一 hazard,发生在 in-process 输出型进程替换消费者面(rubash#3491):复合命令的输出型
>(...)消费者在with_procsub_spawn_plan下运行,plan 由前缀重定向算出(procsub_spawn_plan,取 procsub 位置之前的重定向条目)。bind_procsub_spawn_plan_fd(src/executor/external_setup.rs:2669)的 save 只做裸 Rc clone——PlanFdSave { entry: self.fd_table.entries.get(&fd).cloned(), ... }——随后 bind 在各臂上 retire 被顶掉的描述符:FdTable::close(Closed 臂,两臂都 retire)、set_fd_input_file(File 读臂 / CarrierRead)、open_output(File 写臂 / TruncatedFile / CarrierWrite / CaptureWrite / StreamWrite),retire 经retire_read_arm/retire_write_arm(rubash#3213)立即 close(2)。restore_procsub_spawn_plan_fd(:2790)经entries.insert(saved.fd, entry)把已 retire 的 entry 插回——此后对该 fd 的读写 EBADF,下一次 spawn 的 pin pass 还会把回收了该内核号的描述符 dup2 上去。关键时序:finish 步(
finish_compound_output_process_substitutions)在组自身的重定向作用域恢复之后才跑,所以 plan bind 时 fd 已回到 ambient 文件——plan bind 是唯一 retire 点,钉与 #3706 的组面互不干扰。GNU 锚点
do_redirections (command->redirects, RX_ACTIVE|RX_UNDOABLE),execute_cmd.c:854。fcntl (fd, F_DUPFD, SHELL_FD_BASE),redir.c:965(input)/1082(duplicating)/1144(move),SHELL_FD_BASE 为 10(redir.c:86),由add_undo_redirect记录、undo_redirections拷回。改动
src/executor/fd_table.rs(+108):新增FileFd::duplicate(unixF_DUPFD_CLOEXEC/ Windows 非继承 duplicate)、FdEntry::dup_file_endpoints(仅 File/Coproc 端点 dup;<>两臂共享一个 Rc,保存时沿用读臂的 dup 以保持共享)、FdTable::saved_entry。与 fix(executor): restore fd N after group redirect (Refs #3706) #3723 的三段 helper 是同一份代码(见下“排序说明”)。src/executor/external_setup.rs:bind 的 save 改为saved_entry(fd)?——一个保存点覆盖全部 bind 臂(不按臂打补丁);dup 失败则 bind 失败(GNU REDIRECTION_ERROR),在变异发生前返回;with_procsub_spawn_plan改为返回Result<T, ExecuteError>,某 fd 保存失败时先逆序恢复已绑的保存再返回 Err(GNUundo_partial_redirects式 unwind)。src/executor/pipeline_exec.rs:唯一调用点把 bind 层错误与消费者自身错误同等上报(两层都是ExecuteError)。回归钉
tests/issue3732_procsub_spawn_plan_fd_restore.rs(11 cells):File 读臂 fd 8/fd 3、Closed 臂、TruncatedFile 写臂、append-File 写臂、ReadWrite<>臂、CarrierRead 臂、CarrierWrite 臂、无顶替前缀 control、外部子进程 /proc 面(Linux-only)、<>-close 共享守卫。每个 cell 都先断言消费者跑了(got.txt),再断言 ambient fd 仍服务原文件;除 control 与共享守卫外均为 fail-first。守卫(本轮 fresh 扫描,基底 0587028)
execute_output_process_substitution,与本站点 :2669/:2790 不同函数、最近 989 行)、fix(redirect): open output/append FIFO redirects via cwd anchor in bind phase (Refs #3286) #3735(external_setup.rs :2393,约 259 行外,无 hunk 重叠)。{ ...; } N<redirdoes not restore fd N to its pre-group target #3706,仍 open draft):它在 fd_table.rs 加同一份 helper,本 PR 也加——后合入的一方须删去重复的 helper hunk;产品 hunk 不重叠(fix(executor): restore fd N after group redirect (Refs #3706) #3723 动 command_input_scope.rs / compound_exec.rs / external_finish.rs,本 PR 动 external_setup.rs / pipeline_exec.rs)。本 PR 删除了什么
未删除任何内容(纯增量修复;仅将
with_procsub_spawn_plan的返回由T改为Result<T, ExecuteError>,唯一调用点同步适配;无删除的功能、文件或公开面)。UNVERIFIED-BY-CAPTAIN
构建路线当前全断(Simular box 钱包空 hibernated、X299 与老服务器同断、本 VM 禁本地构建),以下腿全部 OWED,待路线恢复后由队长/Win-agent 补跑:钉 fail-first(base 上红)、修后绿、全量 lib 与 base 逐数对齐、
RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、GNU 5.3 对照探针。本地已跑:
rustfmt --check(4 个触动文件,CLEAN)、git diff --check(CLEAN)、scripts/check-marker-literals.py(OK)、scripts/check-utf8-boundary-hygiene.sh(clean)、scripts/check-api-ledger.py(287 symbols present)。未碰src/lexer/continuation.rs;未改docs/api-ledger.md;未引入 trust/签名/加载期校验机制;LF 行尾。