Repository navigation
Conversation
native-print-process.test.ts 的 #2347 用例在 collectNativePrint reject 后零延迟读 /proc 断言后台后代已回收。内核 do_exit 先 exit_files 关 fd(管道 EOF→流 close→reject)后 exit_notify 置 zombie,调度较慢的 CI runner 上零延迟读取会落在两态之间,看到 stat 仍为 S/R 而误红, 近期已在 8 个不同 PR 的 bun-test 里复发。 新增 waitForReaped 有界等待(5s):zombie/gone 都算已回收,替换两处 零延迟断言;真杀不掉的后代会超时返回 false,断言照咬,不放松不变量。 纯测试改动,生产代码零修改。 Co-Authored-By: Claude Code <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 8, 2026 00:20
Owner
Author
首评|head da9ae8a|结论:0 P1 / 0 P2,可合(纯 test)
这是自动评审的初步意见,最终以维护者审阅为准。 |
This was referenced Nov 8, 2026
Owner
Author
|
补充独立复现证据(复审 P3 已采纳,PR 描述已更新): 我没有直接采信复审的采样,自己在隔离环境(8 核 + 6 满载进程)真跑 我命中的是 P3 处置:
|
Owner
Author
双审结论:本 PR 已被 #3116 完整覆盖,关闭(superseded)感谢这个修复——根因分析与修法方向都正确。但同一条 flake 已由 #3116 用同一思路修复并合入 master,本 PR 同步主干后没有剩余净增量,核对如下。 事实核对(基线:最新 master
双审独立验证(两方各自实跑,非互相采信)
后续
这是自动双审(Claude 首评 + Pure(pi) 复审)的结论,最终以维护者审阅为准。 |
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.
问题
CI 的 bun-test 高频挂在
test/native-print-process.test.ts的用例「does not hang on a descendant that holds both stdin and stdout, and reaps it (#2347)」,断言在 :60/:62(expect(running(pid)).toBe(false),expected false, received true)。近期至少 8 个不同 PR 的 bun-test run 都挂在这一条,是全仓级阻塞 flake。根因
用例通过
collectNativePrint跑一个会留下sleep 30后台后代的 shell,生产代码在print-process.ts里对整个进程组发 SIGTERM(1s 后 SIGKILL 兜底),并在 stdio 管道关闭后 reject。内核
do_exit的顺序是先exit_files()关闭文件描述符、后exit_notify()置 zombie/退出:被杀的后台后代关掉继承的 stdout 时,管道 EOF 让 Node/Bun 的流close触发、collectNativePrintreject,而此刻该后代在/proc/<pid>/stat里还没进入 zombie,可能短暂显示R(仍在 runqueue、拆解早期)或X(task_dead,exit_files()已执行、exit_notify()尚未把状态改成Z的那一瞬)。测试的running()只把Z当已退出,于是在 reject 后零延迟读一次时,R/X都会被错判成「还活着」而误红。这与 #3076 修的 mojo-task9 PROBE 2 是同一类内核状态窗口。为什么本地难复现、CI 高频中:Bun 对直接子进程的流
close会延迟到进程 exit 事件后才送达(实测约 +1ms),本机调度延迟通常盖过这个窗口;但本用例里维持管道的是孙进程(bun 不跟踪它的生命周期),它的 fd 关闭直接驱动流 EOF,在负载高、调度慢的 CI runner 上窗口就暴露出来。实测该用例失败时总耗时只有 15ms,说明进程确实被迅速杀死,只是断言落在内核回收的窄窗里。生产侧的回收逻辑没有问题:进程组信号确实发出,
hardKill1s 兜底也在;测试自己的注释也写了「an orphan may wait a moment for its new parent to reap it」,但断言没有等这「一下」。修法
纯测试改动,生产代码零修改。新增
waitForReaped(pid, 5000):有界轮询直到进程离开 running 态(zombie 或 gone 都算已回收),替换两处零延迟running()断言,与 #3076 的waitFor范式一致。不变量保留:如果后代真的杀不掉(真正的泄漏),5s 有界等待超时后返回 false,断言照样咬红——没有把「多等一会儿」变成无条件放行。
验证
bunx tsc --noEmit、bun run build通过;bun / vitest 双腿单文件 8 测全绿;连同 constrained-invocation、ipc-constrained-invocation 共 3 文件 38 测全绿。collectNativePrint采样,本机能复现:一次 300 轮采样中零延迟/proc读数分布{GONE:297, Z:2, R:1},旧零延迟断言误红 1 次、新有界等待 0 次;另一独立 60 轮采样命中X(task_dead)态 1 次,同样旧断言误红、新断言通过。命中的具体状态字母随采样点落在拆解早期(R)还是exit_files之后(X)而不同,但两者都被只排除Z的running()误判存活,证明竞态真实存在且有界等待是必要修法。sleep 30,waitForReaped(pid, 400)确定性返回 false 且耗时约 400ms(真泄漏咬红);对同一进程 SIGKILL 后确定性返回 true、耗时约 20ms(被信号的正常通过)。expect(...).toBe(true)反转为false,bun 与 vitest 双腿该用例确定性咬红,恢复后转绿。关联
🤖 Generated with Claude Code