Repository navigation
fix(ipc): 关闭 IPC server 时先断开遗留连接,close 不再被拖住数秒 - #3486
Merged
Merged
Conversation
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 15, 2026 08:36
Owner
Author
head 更新为
|
源码与测试注释原称遗留 socket「永不结束、close 永久挂起」并会拖住 daemon 关闭。 实测(Bun 1.4.4):只有 Bun 全局 fetch 的 keep-alive 客户端会留下它,约 6 秒后由运行时 回收;生产 loopback 调用方都走 node:http,不会留下;daemon teardown 不 await close() 且最后显式退出,关闭流程本身从未被拖住。注释改为实测事实,并写明先断开全部连接 会让关闭瞬间的在途请求收到重置(处理函数照常跑完)。 回归用例的单轮关闭上限从 5 秒收紧到 2 秒:变异态要等约 6 秒回收,原上限只留 1 秒 余量。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 86b9b44…149b8e361(3 个提交),同批合入的还有 #3513 #3505,失败不一定由本 PR 引起。
|
This was referenced Nov 17, 2026
|
🚀 Released in v3.59.18 |
kingchao1024
pushed a commit
to kingchao1024/botmux
that referenced
this pull request
Nov 18, 2026
将 botmux-public v3.59.19(165bd3681)合并进本地私有 master(55692db3c), 保留全部本地私有增强(TraeX 压缩版本号、未发送 RPC 头部保留、受信 steer、 受管进程组身份校验、父进程退出收尾、MCP 脱敏环境键等),并吸收上游新能力: worker 终态就绪探针与状态卡残留修复(deepcoldy#3532)、排队轮次接管权限(deepcoldy#3519)、 冷启动/退场回执结算(deepcoldy#3507)、TRAE 草稿与延迟回执隔离(deepcoldy#3506)、 IPC 关闭先断开遗留连接(deepcoldy#3486)、tmux 冷启 pane 秒退保留报错(deepcoldy#3539), 以及 TraeX/dsh/invite/feed-group/antigravity 模型身份等改动。 冲突解决要点: - 私有增强一律保留 ours,上游新增事件分支(traex_model_pool_prune_result、 protected_mcp_secret_channel_result)与清理项并入。 - codex-rpc-engine 中 ack 未绑定原生 turn id 改为抛 CodexRpcDeliveryError('rpc_turn_start_ambiguous')。 - 清理自动合并残留:session-manager 重复 BuiltinSkillEntry 导入、 worker.ts 重复函数块、dashboard-ipc-server 重复 worker-pool 导入、 fake-codex-rpc-server 重复 spawn 导入;worker-pool 删除本地无调用点的 effort 持久化段并回退 adopt 参数。 - 测试夹具补齐 shouldBlockStructuredPromptReady 依赖映射。 验证:tsc 类型检查通过;17 个核心套件 459 通过/3 跳过,剩余失败 (dispatch-user-route 5 项、traex-native-subagent-hook-wiring 6 项) 在合并前基线上完全相同,属既有环境问题,非本次合并回归。
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.
改了什么
src/core/dashboard-ipc-server.ts的IpcServerHandle.close():在server.close()之前先server.closeAllConnections()。同时新增回归用例
test/dashboard-ipc.test.ts > IPC server shutdown after an abandoned request body。为什么(根因,非「测试慢」)
这是生产代码的关闭路径无界等待,最初以测试形态暴露,但不是测试本身的问题:
readJsonBody(dashboard-ipc-server.ts:993)在声明的content-length超过上限时,req.resume()丢弃正文、立刻回 413,不把请求读到末尾。server.close()只停止 accept,其回调等待所有已 accept 的 socket 结束 ⇒ 该 socket 在则close()永不 resolve。后果不只是测试:
daemon.ts:37002的ipcHandle.close()属于 teardown 路径,生产上遇到同一运行时形态同样会挂住。复现证据(隔离探针,非猜测):
close()closeAllConnections()connection: close即:Bun 特有问题(Node 不复现),
closeAllConnections()是确定性的解法,且与仓库既有的释放路径同构 ——src/utils/listen-with-probe.ts:180的releaseAndStep早就在server.close()前先destroyTracked()+closeAllConnections?.(),注释里记的正是「一个僵住 socket 会静默卡死整条释放链」。这里只是让IpcServerHandle.close()对齐同一纪律。影响面
close()语义从「等所有连接自然结束」变为「先断开所有连接再关监听」。IPC 关闭时本就要终止服务,不存在需要让在途请求跑完的调用方(daemon teardown 传完此时已removeDaemonDescriptor)。closeAllConnections(Node ≥ 18.2 / Bun 均有),故用可选调用,缺失时退回原行为。测试验证
bun test test/dashboard-ipc.test.ts→ 397 pass / 0 fail(此前该文件在 bun 全文件模式下PUT /api/bot-reply-style必现 5s 超时,现随根因消失)npx vitest run test/dashboard-ipc.test.ts --project unit --maxWorkers=4→ 397 passed / 3 skippeddashboard-ipc-bad-json、dashboard-ipc-bound-bot-guard、daemon-ipc-session-auth共 147 passedbun run build通过closeAllConnections?.()那一行 →close()能否完成这一行为,不是实现文本;也不再依赖端口生死时序(服务全程监听同一端口)补充:该用例刻意用 32×上限的超大正文(32 MiB 量级)而不是刚过界,因为探针显示未读余量越大挂起越稳定(32 KiB 时约 1/3 轮次复现),这样它才是有区分力的守卫而非抛硬币。
复审更正与补充(head
0aeee6436)上文以下几处与实测(Bun 1.4.4)不符,以本节为准:
closeAllConnections()后,close()稳定在约 6 秒完成(真实startIpcServer5/5 轮 6001–6003ms)——遗留 socket 会被运行时回收,并非永不结束。fetch的 keep-alive 客户端会留下这个 socket:同样的 413 场景,客户端换成 node:http keep-alive Agent 或裸 socket,旧close()1ms 内完成。生产里所有 loopback 调用方都走loopbackFetch(node:http),不会产生这种情况。ipcHandle.close().catch(...),不 await,最后显式process.exit,关闭流程从未被它拖住,「生产上同样会挂住」不成立。实际收益在测试侧:裸bun test(默认 5s 超时)下 master 的PUT /api/bot-reply-style用例必红(5002ms 超时),仓库 bun 腿(180s 超时)下是每次多等约 6 秒。closeAllConnections()会让关闭瞬间仍在处理的请求收到连接重置(实测客户端ECONNRESET,服务端处理函数照常跑完)。唯一的生产调用点是 daemon teardown,客户端本来就要应对 daemon 中途退出。附带效果:dashboard 的/api/eventsSSE 长连接以前会让close()一直等到进程退出,server.once('close')里的清理(停 workspace 回收定时器、释放授权轮询)从来不会执行;现在 teardown 时会执行。本次增量
0aeee6436(只改注释和测试上限)验证(合入最新 master
76d6a9a8后的树b5888bdd)bun run typecheck通过;bun run build在注释修改前的同一合并树上通过(本增量不改代码)bun test test/dashboard-ipc.test.ts(默认 5s 超时):400 pass / 3 skip / 0 failtest/dashboard-ipc.test.ts:397 passed / 3 skipped;相关 IPC 测试 15 个文件(bad-json、bound-bot-guard、daemon-ipc-session-auth、background-execution-ipc 等)全绿closeAllConnections?.()):bun 腿新用例 3/3 在约 2042ms 变红;恢复后 3/3 通过