Skip to content

test: harness teardown — kill idle keep-alive sockets with closeIdleConnections (#3181) - #3183

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-14_fix-3181-teardown-race
Oct 14, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-14_fix-3181-teardown-race

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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=0 cancelledByParent;同分支 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);
  • 定向本地跑:plugin-fork 48/48(ccr-plugin/preemptive-fold-budget/fold-round2-shape/issue1819-regurgitation-guard/preflight-incomplete-json/stream-keepalive 29/29,preflight-fail-fast/issue767-pixel-billing/pi-omp-fork-adopt/e2e-image-billing 46/46),0 cancelled;
  • 全量回归交给远程 CI。

行为变更

tests-only。唯一可观测变化:每个测试尾部不再空等 ~4-5s 的 keep-alive 超时,CI 时长缩短;产品代码零改动。无配置面变化。

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.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-14_fix-3181-teardown-race (cad928a)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3655-pr.3183.e132d38

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3183.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit 448217c into master Oct 14, 2026
36 of 42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.422-master.448217c (rolling master tag).

npm install -g billion-context@0.0.422-master.448217c  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows-22 CI lanes: plugin-fork harness teardown race — idle keep-alive sockets starve server close and the test runner tears down pending tests

1 participant