Repository navigation
executor: bracket per-process latches at the script-child boundary - #3724
Conversation
Refs #3605 `execute_direct_shell_script` emulates GNU's `bash script` fork (execute_cmd.c:6139 shell_execve -> shell.c:429-464 shell_reinitialize) on the shared Executor, so every per-process latch the child mutates must be save/restored at the boundary. Two leaked: - `exit_trap_ran` — trap.c:1128 run_exit_trap's once-only flag. A child script's `trap 'echo EXIT' EXIT` fire left the latch set, so the NEXT in-process child's `( trap T 0; ... )` subshell found it latched and skipped its own EXIT trap. In the macOS execscript gate, exec3.sub's EXIT trap silenced exec12.sub's `exit code: 1` line (and the same leak ate the `foo 0`/`WORKS` lines and exec5's execfail `$?` print downstream). - `exec_replaced` — the exec.def replacement unwind latch. A child's successful in-process `exec` latched it for the parent, suppressing the parent's own EXIT-trap adjudication (trap_exec::run_exit_trap_for_status early-out). Both latches now start clear in the fresh child and the parent's values are restored in the epilogue, matching the process boundary GNU's real child provides (shell.c exit_shell). Verified on macOS arm64 against GNU bash 5.3.20: the reduced pair `trap 'echo E' EXIT` + `main() {( trap T 0; "$@" )}` now prints the subshell trap output, and the execscript gate drops the `foo 0`/`exit code: 1`/`WORKS`/`0` diffs. New pin tests cover both leak directions. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】 机制核查:
F 点:
腿(逐项给数字与名字):
未跑/VOID 的腿:
|
|
【WIN-AGENT-AUDIT】PR #3724 第2轮 — 建议:PASS 机制核查:
腿(逐项数字):
F 点:无(上轮唯一 F 点 = 废钉,已按机制重写并验证 fail-first 有效) 续作记录:
未跑/VOID 的腿:CI 全绿与否待新 head 跑完(约 10 分钟),其余无。 |
|
【WIN-AGENT-AUDIT】PR #3724 第3轮 — 建议:PASS(已合并 83d19f9) 本轮为合入前补验轮(u1),head 与第2轮审计完全一致,未重跑全腿,补齐缺口并复核: 腿:
F 点:无 已执行:gh pr ready → gh pr merge --squash → MERGED,mergeCommit 83d19f9(gh pr view 复核 state=MERGED)。#3605 为伞目录 issue,不关单。 |
Summary
execute_direct_shell_scriptemulates GNU'sbash scriptfork (execute_cmd.c:6139 shell_execve->shell.c:429-464 shell_reinitialize) on the sharedExecutor, so every per-process latch the child mutates must be save/restored at the boundary. Two leaked:exit_trap_ran—trap.c:1128 run_exit_trap's once-only flag. A child script'strap 'echo EXIT' EXITfire left the latch set, so the next in-process child's( trap T 0; ... )subshell found it latched and skipped its own EXIT trap. In the macOS execscript gate this is what silenced exec12.sub'sexit code: 1line after exec3.sub ran (and the same leak ate thefoo 0/WORKSlines and exec5'secho $?).exec_replaced— theexec.defreplacement-unwind latch. A child's successful in-processexeclatched it for the parent, suppressing the parent's own EXIT-trap adjudication (run_exit_trap_for_statusearly-out).Both latches now start clear in the fresh child and the parent's values are restored in the epilogue — matching the process boundary GNU's real child provides (
shell.c exit_shell).Refs #3605
Verification
${THIS_SH} p1.sh(trap 'echo E-EXIT' EXIT; exit 0) followed by${THIS_SH} e12.sh(main() {( trap 'echo TRAP-FIRED' 0; "$@" )}; main f) —TRAP-FIREDnow prints; previously the child died silently rc=1.run-execscriptgate: thefoo 0,exit code: 1x6,WORKSx4, and0vs5diffs are cleared; remaining residuals are the separately-tracked items (E2BIG covered by fix(executor): report E2BIG wording for an oversize command line (Refs unixwin/niubash#993 S4) #3712,exec -a$0, x1–x3b async stdin, coproc, job-control noise).tests/issue3605_child_latch_leak.rs(2 tests) cover the leak in both directions.issue1012_exec_exit_trap,issue1037_shebangless_exec,issue1102_exec_stdin,issue1124_trap_entry_ignore,issue1162..1166_trap_return,issue0085..0290_trap_diag,host_internal_trap_suppression— all green. (issue1175_exec_image_regressionsfails identically on master — known macOS Mach-O exec environment issue, not this change.)本 PR 删除了什么
产品代码无删除:
src/executor/external_finish.rs为纯增量(进/出边界各一组 latch save/restore)。钉文件tests/issue3605_child_latch_leak.rs本轮重写为库 API 驱动,删除了原Command::new(rubash)+${THIS_SH}子进程驱动方式(binary main 会 enable_real_shell_children,子进程间不共享 Executor,无法观测 latch 泄漏,属废钉)。