Repository navigation
test(dashboard-ipc): proof 配额耗尽用例不再依赖 hook 冷启动快于 proof TTL - #2127
Merged
Merged
Conversation
「fails open for a real hook when response-proof quota is exhausted」先用 64 次请求 占满 proof 配额,再冷启动真实 hook。但每个配额位只保留 proof TTL(5s)+1s,由 服务端定时器释放;而这 64 次请求同时占满了 60s 的 nonce 配额。hook 冷启动超过 约 6s 时,它的请求拿到空出的 proof 位,得到带签名的 429,hook 判为 deny,与本例 要测的「配额耗尽、响应无法认证 → 放行」相反。#2102 把 hook 截止时间从 6s 放宽到 25s 之后,失败形态从 hook timed out 变成了这个断言失败(2 核 8 路压测 8/8 必现)。 改为:填充期间拦下服务端启动的、长于 proof TTL 的释放定时器并取消,配额在 hook 请求到达前一直保持占满;afterEach 已会重置配额计数。只改测试。 Refs #2079 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 21, 2026 21:40
原写法在 64 次填充结束后才取消释放定时器;填充本身若慢于 TTL+1s,早期配额位会在循环中途被释放。 Refs #2079 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
已合并 PR #2127 → b9728c2(squash) 门禁:首审与 Pure(pi) 复审都在 head 96822e8 上给出可合(0 P1 / 0 P2;上轮 3 条 P3 中「填充循环自身的时间假设」与「描述口径」已在合前修掉)/ 必需 CI(build、test)与 bun-test、bun-binary* 共 13 项首跑全绿 / 老用户无 breakchange:只改测试 / 落地树与合前在最新 master 上实测的合并树一致(dashboard-ipc 全文件 vitest 340 passed、bun 340 pass) follow-up(复审 P3,不阻断,已写进 PR「已知边界」):
未做:发版、部署(需另行指令) |
|
🚀 Released in v3.49.0 |
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.
改了什么
只改
test/dashboard-ipc.test.ts的「fails open for a real hook when response-proof quota is exhausted and no new trusted proof can be written」一例:填 64 次 proof 配额期间,凡是时长超过 proof TTL 的定时器,一创建就取消。这就是服务端释放配额位的定时器(vitest 下正好 64 个);Bun 下另有每条已结束填充连接的node:httpsocket 超时定时器,连接已经结束,取消它无害。于是配额从填充开始到 hook 请求到达一直保持占满,填充本身和 hook 冷启动多慢都不影响。配额计数由现有的afterEach→__testOnly_resetManagedOriginRuntimeAuthState()重置,不会泄漏到别的用例。生产代码不动。为什么(根因:测试搭法,#2102 的放宽没有解决)
#2079 列的 dashboard-ipc「hook timed out」(近两周 CI 58 次),已由 #2102 把真实 hook 的截止时间从 6s 放宽到 25s,之后 CI 再没出现过这个报错。但放宽只是把失败形态换了一个,本例的时间依赖还在:
所以负载一高,本例就是必红,不是偶尔红:
生产行为是对的:proof 配额满时放行、nonce 配额满时拒绝,正是两条有意的设计(hook 注释:「explicit overload response … is fail-closed」)。问题只在于测试让「配额满」依赖了冷启动比 proof TTL 快。
没有用
vi.useFakeTimers:Bun 的假定时器会连提前保存的真setTimeout一起冻结(实测),hook 退出截止时间(超时时带出子进程 stderr)也会跟着失效。所以改用vi.spyOn(globalThis, 'setTimeout'),只在填充循环期间生效,长于 proof TTL 的定时器创建即取消,其余定时器照常运行;hook 在 spy 恢复之后才启动。已知边界:这个窗口内若有别的长于 proof TTL 的定时器也会被取消,目前只有上面两类;拦截条件(长于 proof TTL)与生产释放延迟(TTL+1s)是隐式联动的,若生产改成不长于 TTL 就释放,拦截会失效、本例回到依赖冷启动速度。影响面
验证
Refs #2079
🤖 Generated with Claude Code