[MERC-3] 修复连接池健康判定,transport error 即时失效连接 - #3
Merged
Conversation
kugouming
force-pushed
the
agent/backend-engineer/161d66292f15
branch
from
August 31, 2026 13:38
685eea4 to
f3f946e
Compare
补齐 Architect review 指出的两处覆盖缺口: 单测(tests/unit/pool/connection-pool.test.ts) - 新增 'transport error invalidates pool connection' 用例组,使用真实 EventEmitter 支撑的 transport mock,覆盖修复的核心卖点 'transport.on(error) → invalidateConnection': · transport emit error 后池 emit connectionFailed 并移除连接 · 下一次 acquire 返回全新连接(id 不同、健康) · 与 markConnectionFailed 并发时不会重复失效(幂等) 之前的 pool 用例仅 mock isConnected(),验证不到这条新路径。 集成测试(tests/integration/backend-recovery.test.ts + fixtures/mock-stdio-mcp.cjs) - 用真实 ConnectionPool + 真实 StdioTransport 拉起真实后端子进程,覆盖 '后端死亡 → 池恢复 → tools/list 重新拿到工具' 端到端链路: · stdio 后端以 code 0 退出后,下一次 tools/list 经新连接成功返回原 N 工具 · stdio 后端被 SIGKILL 杀死后同样恢复 · maxConnections=1 时死连接被驱逐而非占满名额导致挂起 这条链路此前无任何 E2E 覆盖。
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.
变更内容
修复后台 server 模式长时间运行后内部服务连接断开、无法获取工具的问题。根因是出站连接池将已进入 ERROR 的 transport 仍当作健康连接复用。
src/pool/connection-pool.ts):isConnectionHealthy要求transport.isConnected(),SSE/HTTP transport 进入 ERROR、stdio 进程退出后立即判为不健康。src/pool/connection-pool.ts):findIdleConnection只返回健康 idle 连接;发现不健康连接通过新增invalidateConnection同步移出池、关闭 transport、唤醒等待队列。src/pool/connection-pool.ts):transporterrorlistener 直接失效对应连接并触发processQueue,缩短故障窗口。src/transport/stdio.ts):非主动关闭的退出(含 code 0、signal)标记 transport ERROR,关闭 receive 侧并 settle 等待中的 receiver。验证
npm run typecheck/lint/format:check全部通过npm test938/938 通过(含新增回归测试)Closes #2