Repository navigation
Bare wait: record sibling deaths between per-pid waits - #3319
Merged
Merged
Conversation
GNU's bare wait is a scan/wait loop (jobs.c:2796-2867 wait_for_background_pids): waitchld, driven from wait_for's blocking loop, records every exited child, so a job whose death landed while an earlier job was being waited is seen DEAD when the scan reaches it and is never passed to wait_for_single_pid; the notified mark (jobs.c:3434-3437) belongs only to jobs the wait actually blocked on, and the tail force-mark exempts the last asynchronous pid's job (jobs.c:5196 mark_dead_jobs_as_notified). The per-pid pass here went straight to wait_for_background_pid, whose live arm reaps and marks a child that had already exited before its turn came — an instant reap wearing a waited mark — so the last job was consumed and settle_bare_wait had nothing left to keep. Run the observed refresh (the poll model's recording point) at the head of every pass iteration: a death the sweep records takes the completed arm (no wait-mark), and only a job the pass genuinely blocks on is marked. Verified: issue2340 stem 6/3 on the base, 9/9 after, three runs; seed construction 30/30 survivor against GNU's 19/30 on the same loaded box.
caomengxuan666
marked this pull request as ready for review
November 11, 2026 09:14
caomengxuan666
added a commit
that referenced
this pull request
Nov 11, 2026
第二波钉先行 J1 组(#2340 #2697 #2769 #2777):修法面被在飞 PR #3110(#3051,jobs/table 同面)占着,本 PR 只落钉 + 根因/修法设计(车道 REPORT),不写产品代码。门开后修法车道按 REPORT 设计动。 Refs #2697 — tests/issue2697_subshell_member_death_notice_regressions.rs(5 格):前台子 shell 成员被 SIGXFSZ 杀死时期望裸成员文本(通知由子 shell 自身作业表视角打印);exec 形与后台子 shell 作业两控制格期望整段子 shell 文本。 Refs #2769 — tests/issue2769_death_notice_line_stamp_regressions.rs(5 格):边界通知行戳 = 读位置行(下一命令行 / EOF 末行 +1 / 多行复合的终点行);前台通知格守即时打印方向(戳死亡命令本行)。 Refs #2777 — tests/issue2777_stopped_job_state_regressions.rs(7 格):深审 B4 原会话(kill -STOP $! 后立即 exit)期望 "There are stopped jobs.";含 jobs 列表状态格、STOP→CONT 链路格、TSTP 形、PTY 无观察点格、脚本模式控制格(GNU 脚本内显 Running,防过修)。 Refs #2340 — 已由 56dc41a 修复且钉已在仓(tests/issue2340_wait_job_retention_regressions.rs,9 格),本 PR 不含 #2340 新钉;本车道在基底上复跑既有钉存证,供关单裁决。 期望值全部以 GNU bash 5.3.20 oracle 脚本文件实测为准(2026-11-09);fail-first 逐格结果见车道 REPORT。 ## 本 PR 删除了什么 无(纯测试新增)。净行数 +960 行(3 个新测试文件),未删除任何文件或代码。 ## 队长复核附记(rebase 轮,2026-11-11) PR #3319(Refs #2340 的修法本体)合入 master(71de8b76)后,本 PR 头 c2a5ab1 与现 master 的组合头(eca5e5ca,合并无冲突、产品面与 master 逐字同)上四茎复跑,卷宗 review-3180-rebase/CAPTAIN-VERIFY.md: - issue2340 茎 9/9 四连绿;窗口强制探针(%1 于 0.3s 处杀 %2、死亡落在 wait 阻塞期内)组合头 5/5 输出 done 1、与 GNU oracle 5/5 同形,基底 0/5。基底茎采样另见 survivor 删除签名三形(8/1、6/3、8/1)。 - issue2697 茎双边皆 1 过 4 红、红名集与登记四名逐字同;issue2777 茎组合头 5 过 2 红两轮(登记两名,皆红于 kill 后 wait 状态 W 断言),整茎约 16.4 秒有界完成;issue2769 茎双边皆 2 过 3 红,eof 格经多采样裁定为 EOF 死亡通知的出现竞速(失败原文为通知缺席、戳值恒对,GNU 同构造 40/40 确定),属既存产品面、非本轮引入。 - lib 组合头 1243 过 0 败 4 忽略、基底 1206 过 0 败 4 忽略,失败名集双边差为空;fmt、全树 UTF-8 卫生、marker-lint 皆 rc=0;RUSTFLAGS 带 -D warnings 的 lib 与 bins 检查 rc=0(带旗痕迹亲核),四茎逐个 scoped 同旗检查 rc=0;全树 tests 同旗检查的红仅在 master 既存 tests 警告族(issue2584、issue2514 两文件,不在本 PR diff 内)。 - 本 PR 合入后,#2340 由队长以证据评论另行处置;#2697、#2769、#2777 保持开启,钉即其 fail-first 证据。
This was referenced Nov 11, 2026
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 #2340
Problem
A bare
waitafterkill %1 %2deleted the last asynchronous job's entry even when both deaths preceded the wait. The seed constructionprinted
done/0; GNU bash 5.3.20 printsdone/1, because the job holding$!survives a bare wait that never had to block on it.GNU anchors
jobs.c:2796-2867wait_for_background_pids: the bare wait is a scan/wait loop; only RUNNING jobs are selected, andwaitchldrecords every exited child whilewait_forblocks on the selected one.jobs.c:3401/jobs.c:3434-3437wait_for_job: a job the wait actually waited for is markedJ_NOTIFIEDafterwards.jobs.c:5179/jobs.c:5196mark_dead_jobs_as_notified: the bare wait's tail force-mark exempts the job whose last pid equalslast_asynchronous_pid.jobs.c:1303cleanup_dead_jobs: retires DEAD jobs that areJ_NOTIFIED.Mechanism change
One statement in the bare-wait arm of
execute_wait_inner(src/executor/job_builtins.rs): run the observed background-job refresh at the head of every per-pid pass iteration. The refresh is the poll model's recording point — thewaitchldanalogue. A death the sweep records takes the completed arm ofwait_for_background_pid, which carries no wait-mark. Before this change, such a death fell into the live arm as an instant reap and was marked there, consuming the last-asynchronous job beforesettle_bare_waitcould keep it. Only a job the pass genuinely blocks on receives the waited mark now. No operand-wait path changes; no per-cell special cases.Verification
42182809(the stem is already on master): 6 passed / 3 failed — the two registered stable reds plus the main-shell listing cell.jobs_listing_shows_stopped_after_observation,tstp_stop_also_shows_stopped); 2769 identical on both trees (2 passed / 3 failed, same three names); 2697 identical on both trees (1 passed / 4 failed, same four red names:fg_subshell_exec_death_names_the_whole_subshell_text,fg_subshell_member_death_names_the_member_command,fg_subshell_member_death_names_whichever_member_is_running,plain_member_death_names_the_member_command).--bin rubashfirst): 1243 passed / 0 failed / 4 ignored on both trees; failure name-set difference is empty.RUSTFLAGS="-D warnings"check rc=0 with 37 flagged rustc invocations as flag proof;cargo fmt --checkrc=0; UTF-8 boundary hygiene clean;cargo check --testsrc=0. The diff holds nolibc::(no cross-target legs owed) and touches no marker faces (marker lint not owed).Deletions
None. The change is a single added statement plus its explanatory comment; no code, tests, or files are removed.