Repository navigation
[PR] fix(#5167): poll the stale-rotation wait on fresh connections so a draining resident reads as released - #5169
Merged
Conversation
…aining resident reads as released During an auto-update turnover the old resident accepts /__bili/shutdown and frees its LISTENER within milliseconds, but keeps answering pooled keep-alive sockets while it drains (worst case (1+10)x10s post-#3890). Both rotation waits polled liveness with Node's global fetch, whose undici pool reuses exactly those sockets (poll cadence 200/500ms << the server's 5s keepAliveTimeout), so a draining resident read as alive for the whole 12s budget. The false negative sent dsh hosts into attach-anyway (riding the doomed old instance while others used the new spawn) and the launcher into the spawn ladder while the port was actually free — two live processes writing one machine-global session store. Every rotation request (shutdown POST included) now sends Connection: close, so "answers" means "the listener still accepts" — the real port-release signal; the stale 12s-budget comment is corrected to match (listener close, not process exit). tests/issue5167-drain-aware-rotation .test.ts pins both paths against REAL draining http servers (no fetch mocks) and a single-connection dispatcher that reproduces the pooled topology: pre-fix it consumes the full 12s deadline, post-fix it returns in milliseconds; a wedged holder that truly keeps its listener still times out into the fallback.
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6847-pr.5169.09f3af7This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5169.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.921-master.a8c907d # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 30, 2026
Closed
Louie0806
added a commit
to Louie0806/billion-context
that referenced
this pull request
Oct 30, 2026
…iagnostic text `d47c6dcf` (ranxianglei#5103, "make startup-failure paths self-contained and actionable") extended the squatter diagnostic with an actionable tail: ... waiting for the spawned instance to report its real origin ; if that never happens, kill pid N or set native.attachExternal=true / BILI_NATIVE_ATTACH_EXTERNAL=1 to attach to the holder instead The message moved, the assertion did not: `tests/launcher.test.ts:8191` still pinned the pre-ranxianglei#5103 string, so the two ranxianglei#3575 tests have failed on every commit carrying both — master HEAD `6db59068` included. Verified by reproduction, not by reading the diff: * master HEAD 6db5906, tests/launcher.test.ts -> 341 pass / 2 fail * pristine upstream/master 27b3155 -> 341 pass / 2 fail * both failing with the one-string diff above * after this one-line fix -> 344 pass / 0 fail This is one of the fixed failure set ranxianglei#5195 attributes to `ranxianglei#5169`, but the bisect there has no clean green baseline: `4bb2bc1e`, cited as "fully green", actually has exactly ONE `test (` check and it is `cancelled` (verified via `commits/4bb2bc1ed/check-runs`), so its shards never ran. Recording that separately on ranxianglei#5195.
Louie0806
added a commit
to Louie0806/billion-context
that referenced
this pull request
Oct 30, 2026
…iagnostic text `d47c6dcf` (ranxianglei#5103, "make startup-failure paths self-contained and actionable") extended the squatter diagnostic with an actionable tail: ... waiting for the spawned instance to report its real origin ; if that never happens, kill pid N or set native.attachExternal=true / BILI_NATIVE_ATTACH_EXTERNAL=1 to attach to the holder instead The message moved, the assertion did not: `tests/launcher.test.ts:8191` still pinned the pre-ranxianglei#5103 string, so the two ranxianglei#3575 tests have failed on every commit carrying both — master HEAD `6db59068` included. Verified by reproduction, not by reading the diff: * master HEAD 6db5906, tests/launcher.test.ts -> 341 pass / 2 fail * pristine upstream/master 27b3155 -> 341 pass / 2 fail * both failing with the one-string diff above * after this one-line fix -> 344 pass / 0 fail This is one of the fixed failure set ranxianglei#5195 attributes to `ranxianglei#5169`, but the bisect there has no clean green baseline: `4bb2bc1e`, cited as "fully green", actually has exactly ONE `test (` check and it is `cancelled` (verified via `commits/4bb2bc1ed/check-runs`), so its shards never ran. Recording that separately on ranxianglei#5195.
This was referenced Oct 31, 2026
This was referenced Oct 31, 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.
Fixes #5167
什么坏了(一句话)
自动升级换代时,旋转(rotation)等待用连接池里的 keep-alive 连接去问「旧实例还活着吗」,而排水中的旧实例「listener 已关、存量连接照常应答」——于是被误判成「没退出」,12 秒后假失败:dsh 宿主 attach-anyway 骑上将被强退的旧实例、launcher 走 spawn 阶梯,新旧两个进程同时写一份 machine-global 会话存储。
根因(机制链)
POST /__bili/shutdown后执行server.close():listener 毫秒级释放(口已可被新 child 绑定),但存量 keep-alive 连接继续被服务——这是排水的本意([Bug] Windows: Proxy falsely detects parent-gone and self-terminates on every forwarded request (same live PID triggered | [Bug] Windows:代理每转发一次请求就误判 parent-gone 自杀(同一存活 PID 在 2.5h 内触发 12 次) #3890 后最坏 (1+10)×10s 才退进程)。src/launcher.tsrotateStalePredecessor,每 200msfetchHealthInfo;src/agent/dsh-native.tsrotatePinnedStaleProxy,每 500msfetchProxyVersion;两者都用 Node 全局 fetch(undici 按 origin 池化),轮询节拍远小于服务端
keepAliveTimeout = 5s,探测永远落在预热过的池化 socket 上 → 排水中的实例「应答如常」。src/agent/dsh-native.ts:809attach-anyway;launcherfalling back to the normal spawn ladder。实测拓扑(本地探针日志,见 issue):预热探测 + shutdown POST 共用一个池化 socket,该 socket 在 close() 时刻有 in-flight 请求 → 存活并持续应答后续轮询。STALE_ROTATION_WAIT_MS的注释(> the responder's 10s force-exit backstop)在 [Bug] Windows: Proxy falsely detects parent-gone and self-terminates on every forwarded request (same live PID triggered | [Bug] Windows:代理每转发一次请求就误判 parent-gone 自杀(同一存活 PID 在 2.5h 内触发 12 次) #3890 后已过时;且预算语义本身错位——口释放信号是 listener 关闭,不是进程退出。修法
旋转等待涉及的全部请求(含 shutdown POST 自身)改带
Connection: close,每轮全新连接,「应答」重新等于「listener 还在收新连接」:requestInstanceShutdown(launcher.ts):加connection: close;fetchHealthInfoNoReuse(默认 =fetchHealthInfoDefault带 noKeepAlive;发现路径probeLiveInstances的池化探测不变,零性能影响);fetchProxyVersion(shared.ts):加可选init透传(纯 additive,其他调用方不变);rotatePinnedStaleProxy轮询带connection: close;still accepts fresh connections (listener open))。范围外(owner 已有待裁决策,本 PR 不碰):新实例绑定后旧实例排水+exit-flush 期间的存储重叠窗(#5068 选项 B / #5018);attach-anyway 决策本身(#4705 相关)。
测试
tests/issue5167-drain-aware-rotation.test.ts,4 例,全部走真实 http 排水服务器(无 fetch mock):srv.close(),存量连接继续服务)必须被读作「已释放」→ 正常 spawn 接管,drain-wait 有界(≤2 ticks),无「timed out」误报;true且毫秒级完成(不再是 12s 假超时);用undici.Agent({ connections: 1 })全局 dispatcher 钉住单连接池化拓扑——修复前该用例确定性红(12.3s,每轮池化轮询都被应答),修复后绿;false(用_setPinnedRotationWaitForTest缩短 deadline,负例不拖慢 CI)。既有回归全绿:#3544 旋转套件 20/20、launcher 343/343、dsh 相关 17 个套件 0 失败、
npm run typecheck干净。