Repository navigation
test: harness teardown — kill idle keep-alive sockets with closeIdleConnections (#3181) - #3183
Merged
Merged
Conversation
Test harnesses awaited server 'close' after only calling close(), leaving teardown completion to the client-side keep-alive timeout (~4s undici pool). In that window the event loop can drain and node:test cancels every pending test in the file ('Promise resolution is still pending but the event loop has already resolved', cancelledByParent cascade) — reproducible 3x on windows-22 for tests/plugin-fork.test.ts via PR #3166 CI.
Fix: call closeIdleConnections() on proxy and upstream right after close() in every paired teardown (138 test files, ~400 sites), so the close event fires immediately. Tests-only; no product code touched.
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3655-pr.3183.e132d38This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3183.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.422-master.448217c # this exact build
npm install -g billion-context@master # always the newest merged build
|
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.
Closes #3181
问题
测试 harness 的
close()只调proxy.close()+upstream.close()然后等close事件,但不杀空闲 keep-alive socket。测试里的 fetch(undici)把连接池里的 socket 保活约 4s,而http.Server.close()不主动断空闲连接——拆除完成被押在客户端保活超时上。在这个 4-5s 窗口里事件循环只剩这一个句柄,一旦它以不利方式消亡(undici 定时器到期/socket 半开),循环排干,node:test 以Promise resolution is still pending but the event loop has already resolved级联取消整个文件的全部测试。实证:PR #3166 CI(windows-latest, node 22, shard 3)三连复现——
tests/plugin-fork.test.ts第 1347 个测试 duration ≈4.8s(≈ undici keepAliveTimeout 4s + 启动),后续 47 个测试全部 duration=0cancelledByParent;同分支 windows-24/ubuntu 全绿、本地 linux 48/48 绿。业务路径全通(acp-usage 已打印),卡的是拆除。修复(tests-only)
所有「先 fetch 打流量、再 close 后 await close 事件」的 paired teardown,在
close()之后立即补closeIdleConnections?.(),空闲 socket 当场销毁、close 事件马上发出,竞态窗口消失。http.Server.closeIdleConnections自 node ≥18.2 存在,engines node>=20 满足;?.与既有惯例一致(responses-seam-probes.test.ts已用closeAllConnections?.())。覆盖 138 个测试文件、约 400 处 teardown:内联 harness return(plugin-fork/pi-omp-fork-adopt/fork-nudge-deadzone/dsh-fork-adopt/session-continuity-proof/plugin-status-provenance/context-provenance-outbound/opencode-fork-adopt/fork-replica-convergence)、顺序 await 块、
Promise.allSettled变体、共享closeAll(...http.Server[])helper(preflight-incomplete-json/preflight-nonstream-400-probe/preflight-stream-summary-config/issue1993-preflight-400/fix-488-multimodal/fix-781-summary-images)等全部形状。有意不动的:未等待 close 事件的 unawaited close(无 pending promise,不会触发该失败模式);net.Server 接收端(main-path-transport-retry 的 closedPort/holder,无此方法);已有
closeAllConnections处理的(codex-live-window、web-logs-view、responses-seam-probes);graceful-close.test.ts(测产品 graceful-close 语义,非 harness 拆除)。验证
npm run typecheck干净(kernel + pi-subagents + src + tests);行为变更
tests-only。唯一可观测变化:每个测试尾部不再空等 ~4-5s 的 keep-alive 超时,CI 时长缩短;产品代码零改动。无配置面变化。