Repository navigation
fix(executor): termsig death during comsub, blocking read and simulated-exec waits (Refs #3401) - #3455
Merged
Conversation
…ed-exec waits (Refs #3401) Face 1 (comsub): the clone is a conduit, not a judge — its trap table is reset, so it records a parent-death delivery raw and the teardown re-queues it for the parent's next boundary poll (EXIT trap first, then death by the signal; jobs.c:3064 wait_for CHECK_TERMSIG). The pin shape x=$(/usr/bin/sleep 5) is served by the external-command fast path, not the clone, so its wait_with_output is replaced by a reader thread plus 10ms try_wait slices classifying each delivery with the shared &self verdict. Un-gates term-comsub. Face 2 (blocking read): the sliced-readability gate is generalized to all blocking reads (not just the interactive SIGINT guard); each 50ms slice drains the termsig mailbox (read.def:766 CHECK_TERMSIG after every read attempt). Adds term-read and term-read-t cells. Face 3 (simulated exec): the executor is threaded through the exec builtin's spawn chain (13 trap_exec call sites); both simulated waits now run through wait_fg_child_draining (execute_cmd.c:6126 exec_builtin -> shell_execve has no simulated-wait layer). Adds the term-sim-exec cell ($(exec ...) via the capture-bound fd table). Pins: tests/issue3284_engine_wait_termsig_regressions.rs 9 -> 12 cells (term-comsub un-gated, term-read, term-read-t, term-sim-exec). Base fail-first on c28a9dd: 7 passed / 1 failed (hup-ext, inherited SIG_IGN environment) / 1 ignored; comsub FAILED at 5.26s.
…it, Option-thread the executor (Refs #3401) - wait_fg_child_draining lives in external_inner; re-export it from crate::executor (same pattern as spawn_error_diagnostic) so the builtins::exec waits resolve (E0425 x2). - The execute_with_* chain takes Option<&mut Executor>: Some on the engine path (13 trap_exec sites, explicit reborrow), None on the standalone execute() entry, which has no session — there the bare wait is correct, because no mailbox defers the signal and the disposition is SIG_DFL, so the process dies at delivery exactly as GNU does for an untrapped termsig. execute() keeps its public io::Result<i32> contract via a boundary map (IoError passthrough). - Fix the 5 cargo fmt --check violations the first commit left (exec.rs, command_substitution.rs, trap_exec.rs x2, pin stem).
…io call (Refs #3401) - Some(&mut *self) activates its mutable reborrow at once (no two-phase borrow through Some), so the later self.exec_inherited_stdin()? argument is E0502 (CI Rust tests, trap_exec.rs:4578). Hoist the resolve before the call, mirroring the else branch below, which already hoists it the same way.
… too (Refs #3401) - pending_termsig_verdict never returned death on the fast path: comsub_parent_termsig_armed read only the snapshot Cell, which is always false on the parent executor (initialised false, only ever set when a clone is built). The pin shape x=$(/usr/bin/sleep 5) runs on the parent, so the TERM was re-queued slice after slice and the wait rode out the whole child (term-comsub died at 5.05s on head ddd41e5; probe comsub 5.06s vs GNU 0.80s). - EXIT-armed now has two sources: the clone's snapshot Cell (the clone's only source — its trap table was reset) OR the live trap table, exactly like termsig_death_armed. On the parent this makes the verdict identical to termsig_death_armed; on the clone the snapshot still arms it.
…t (Refs #3401) - wait_fg_child_draining is #[cfg(unix)], so the ungated re-export in executor/mod.rs is E0432 on Windows (CI run 43278490674, both windows-latest legs; Linux legs all pass). The builtins::exec call sites are not cfg-gated, so gating the re-export would only move the error to E0425 at the calls. Add a #[cfg(not(unix))] twin that is the plain blocking wait — there is no termsig/mailbox model off unix, the same shape the fast path's #[cfg(not(unix))] arm and the non-unix branches of wait_external_child use. - Fix the one cargo fmt --check violation the live-table fix left (trap_exec.rs:2730, rustfmt's own layout for the || chain).
Member
Author
复核:PASS(Refs #3401,终头
|
caomengxuan666
marked this pull request as ready for review
November 14, 2026 17:01
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
…(Refs #3211) (#3220) Refs #3211 ## 根因(机制定性) 动态变量整表复合赋值缺属主落点钩子。GNU 把 BASH_ALIASES / BASH_CMDS 注册为带元素 assign hook 的动态变量(variables.c:1882-1897 `initialize_dynamic_variables`): | 变量 | hook | 语义 | | --- | --- | --- | | BASH_ALIASES | assign_aliasvar(variables.c:1785) | `valid_alias_name` 校验后 `add_alias`;非法名报错跳过该元素、其余照落、语句 rc 不变 | | BASH_CMDS | assign_hashcmd(variables.c:1715) | `phash_insert(key, value, 0, 0)`:被点名条目 hits 重置、未点名条目原样保留 | 整表赋值无第二条路:`subst.c:3441 do_compound_assignment` → `arrayfunc.c:700 assign_compound_array_list` 逐元素经 `bind_assoc_var_internal` / `bind_array_var_internal` 调钩子;标量 绑定走 `bind_variable_internal` 的 assign_func 臂、以 key `"0"` 调 钩子(variables.c:3140),`+=` 标量先 `make_variable_value` ASS_APPEND 读现值拼接(variables.c:3328)。非追加复合形只换 cell 投影、**从不清属主表**——列表外属主条目保留。declare / typeset / export 的操作数绑定同走 bind_variable 家族、钩子同路。 rubash 侧:#3107 的 `sync_dynamic_assoc_vars` 只在「属主 → 镜像」 方向发布;整表赋值落通用路径只写镜像 + typed 存储,下一命令边界 `sync_dynamic_assoc_cells` 对账时以未被触碰的属主表重建两者,赋值 被丢弃。对照 DIRSTACK 早有属主落点门 `apply_dirstack_assignment`, assoc 对偶一直缺位——本 PR 补上。 ## 普查(全部动态变量整表赋值落点,GNU 探针 27 格实测) | 变量 | GNU 机制 | rubash 处置 | | --- | --- | --- | | BASH_ALIASES | assign_aliasvar 逐元素落 alias 表 | **本 PR 新增门**(复合/标量/追加/kvpair/列表内 `[k]+=`) | | BASH_CMDS | assign_hashcmd 逐元素落 hash 表 | **本 PR 新增门**(同上;hits 语义 = 只重置被点名条目) | | DIRSTACK | assign_dirstack → set_dirstack_element([0]/越界忽略) | 既有门(回归锁钉覆盖) | | GROUPS / BASH_ARGC / BASH_ARGV / BASH_SOURCE / BASH_LINENO / FUNCNAME | null_array_assign no-op + att_noassign | 既有 noassign 臂吞(非追加形);追加形普查与残余见车道 REPORT | | BASH_REMATCH | 无钩子普通数组(match 时重建) | 通用路径即正道 | | PIPESTATUS | 无钩子普通数组;赋值语句自身管线状态在边界覆写读值 | 通用路径 + 既有 note 机制 | declare / typeset / export 三门与 local 影子、unset 后整表赋值的 基底行为由车道普查对基底二进制逐格核对后回填(见 `~/workspace/fix-3211/REPORT.md` §2,工作区文件不入仓)。 ## 修法 `apply_shell_assignment_inner` 在 DIRSTACK 臂旁加动态 assoc 门 `apply_dynamic_assoc_assignment`(`dynamic_arrays.rs`,与 DIRSTACK 门同居):复合形经与通用路径同一 `rewrite_compound_element_subscripts` + `append_assoc_value` 扫描 后逐条路由属主(aliases 表 / `set_hashed_path`);`=` 形以空表为 扫描种子(列表内追加在本列表内组合)、`+=` 形以属主现表为种子算 终值且只路由列表点名的键;标量形 = key `"0"` 单条,`+=` 先读属主 [0] 拼接。门控与 DIRSTACK 同口径:readonly 由上游臂先行拒绝, unset 标记 / local / tempenv 影子让位普通 cell。收尾统一 `sync_dynamic_assoc_vars()` 发布。 回归钉 `tests/issue3211_dynamic_whole_assignment.rs`:普查每个 动态变量的整表赋值形 + 元素赋值回归锁 + unset 后普通变量锁。 ## 验证(队长已核,见 PR #3220 评论 6880965406) - 合并形钉(终头 `3e7c069f`,update-branch 至 `#3455` 合入后的尖 `12aa434e`):**10/10**。 - Fail-first(顶-up 形,基底 `c01a5417`):**3 passed / 7 failed**——7 红格恰为门控格,3 守卫格在基底上绿;翻转真实(基底 3/7 → 合并头 10/10)。 - 尖端 sanity:被拆出的 #3573 面格在尖 `ca89c83a` 上 **1/1** 绿(已由合入的 #3577 修复),故本钉删该格安全;邻居 #3573 钉在终头上 **14/14**。 - Lib 双边:终头 1249/0/4 vs 基底 1206/0/4,失败名集差 **∅**(两边皆 0 FAILED 行)。 - 交集 vs 活尖:两产品文件 hunk 级无重叠(本 PR 的 hunk 在 dynamic_arrays.rs:1870、temporary_assignments.rs:1783;区间内最近 hunk 相距 ≥51 行);update-branch 已干净应用。 ## 本 PR 删除了什么 无删除:纯新增(赋值门 + 回归钉)。通用路径对这两个变量名的整表 赋值自本 PR 起不可达(由门接管),但代码不删——影子/unset 情形仍 走通用路径绑定普通 cell。
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
…(Refs #3500) ## Summary A bad substitution inside a compound-assignment element was diagnosed with the `${...}` fragment instead of the element word. GNU quotes the whole element and reports the word being expanded, e.g. `a=([0]=${-x})` → `\[0\]=${-x}`. ## Root cause `subscripted_parameter_element` hands the RHS to `whole_word_parameter_single_value`, whose `has_word_operator` arm misjudges `${-x}` (empty `var_name` at position 0) and expands it standalone with no pending diagnostic word installed, so `expand_braced_parameter_word` falls back to the synthesized `${-x}` fragment. The plain-element path had the same gap (the walker default names the raw token, without `quote_assign`'s `\[sub\]` quoting). ## Fix - New `compound_element_diag_word` (module level, mirrors GNU `quote_assign`): indexed `[sub]=value` → `\[sub\]=value`; assoc elements → the bare value; a quoted value keeps the fragment's own word. - The element word is installed as the pending diagnostic word at the two element-expansion sites (`subscripted_parameter_element`, `compound_plain_element_value[_fields]`), install-if-absent. - An `assoc` parameter is threaded through `expand_compound_positional_at_assignment[_bare]` (4 call sites), computed by new `compound_assignment_is_assoc` (live `ASSOC_VARS` marking OR the declare-assoc hint). - New declare-assoc thread-local hint (`DECLARE_ASSOC_HINT` + RAII guard), installed by the `declare_assoc_operand_names()` scan in `command_prepare.rs`, covering the `declare -A` command-word expansion path, which runs before the declare builtin. - Bare (eval-argument) flatten installs no word: documented residual, not fixed here. GNU anchors: `arrayfunc.c:557/:581/:594-599/:606/:630/:938-977/:1108-1129`; `subst.c:10278`. ## Regression pin `tests/issue3500_compound_elem_diag_word.rs` — 19 cells (10 fix shapes + 6 guard shapes + 2 quiet guards + 1 first-bad-wins). Expectations verified against GNU bash 5.3.20. ## Verification (captain-verified legs) - Merged head `d11ffbcf` (update-branch of `00c0a07` onto tip `021705cf`, three update-branch rounds: `8eb07872` (#3510), `12aa434e` (#3455, disjoint files), `021705cf` (#3220, disjoint files); intersection `{src/executor/assignment_expansion.rs}` via #3599, hunks ≥164 lines apart, no overlap): pin **19/19**; same-file neighbor issue3501 pin **68/68**; adjacent assoc-face issue3573 pin **14/14**. - Fail-first (top-up form on base `11719895`): pin 11/19 — 8 red, each reporting `Some("${-x}")` where the element word is expected. - Neighbor `array_compound_quote_regressions` 17/17 on head. - Full lib bilateral (bin built first): base 1247 passed / 0 failed / 4 ignored; merged head 1249 passed / 0 failed / 4 ignored — failure name-set diff empty (the +2 are the tip's Mach-O unit tests from #3510). - `RUSTFLAGS="-D warnings" cargo check` RC=0, 0 warnings; `cargo fmt --check` RC=0; utf8-boundary hygiene clean. - Head CI run `43619058744` (on `10da84b4`, the second update-branched head): 3 failing jobs, sole FAILED name `issue2875` (known baseline). A fresh CI run starts on the final head `d11ffbcf` from the third update-branch; it differs from `10da84b4` only by the disjoint #3220 merge. - `continuation.rs` untouched. Refs #3500 ## 本 PR 删除了什么 Nothing — purely additive fix plus the new regression pin. No code, test, file, or behaviour removed.
This was referenced Nov 14, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3401 (P2, #3284 residual family; Uarz resting, captain temporary takeover).
What this fixes
A terminating signal (TERM/HUP) delivered while the shell waits in one of three faces rode out the whole wait instead of killing the shell promptly in GNU order (EXIT trap first, then death by the signal; jobs.c:3064 wait_for CHECK_TERMSIG, sig.c:590 termsig_handler).
comsub_termsig_pending) and the teardown re-queues it for the parent's next boundary poll. The pin shapex=$(/usr/bin/sleep 5)is served by the external-command fast path, not the clone, so that path'swait_with_outputis replaced by a reader thread plus 10mstry_waitslices classifying each delivery with the shared&selfverdict (pending_termsig_verdict).readwait. The sliced-readability gate is generalized to all blocking reads (not just the interactive SIGINT guard); each 50ms slice drains the termsig mailbox (read.def:766 CHECK_TERMSIG after every read attempt).-tdeadline loop gets the same per-slice drain.wait_fg_child_draining(execute_cmd.c:6126 exec_builtin -> shell_execve has no simulated-wait layer). The capture path additionally drains its pipes on reader threads so large output cannot deadlock.Pins
tests/issue3284_engine_wait_termsig_regressions.rs, 9 -> 12 cells: term-comsub un-gated, plus new term-read, term-read-t, term-sim-exec ($(exec ...) via the capture-bound fd table). Base fail-first on c28a9dd: 7 passed / 1 failed (hup-ext, inherited SIG_IGN environment in the driver session) / 1 ignored; comsub FAILED at 5.26s. Box head legs pending (box disk at 100% at push time).
本 PR 删除了什么
with_exec_diag_stderr辅助函数(src/executor/trap_exec.rs):其四个调用方已改为 inline take/restore(闭包无法同时借&mut self.stderr_capture与&mut self执行器参数),删除后无调用方;inline 形保留了原 helper 的关键保证——capture slot 在错误传播前恢复。