[Bug] mcp-client: activeServerNames 生命周期泄漏导致无法创建新会话 #3984
tang-zhilei
started this conversation in
General
Replies: 1 comment
|
我们针对这个问题做了独立的深度分析,已发布为单独的分析帖(含源码级根因修正、设计层审视与方案评估): 分析帖:[Analysis] mcp-client activeServerNames: root cause is a scope mismatch, not a missed cleanup — and the proposed "defensive cleanup" is unsafe 三个补充结论(详见分析帖):
验证环境: EN (short version)We published a separate follow-up analysis on this issue (root-cause correction, design-level scope mismatch, and a caution on the proposed fix): [Analysis] mcp-client activeServerNames: root cause is a scope mismatch, not a missed cleanup — and the proposed "defensive cleanup" is unsafe Key points:
Verified on |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
问题描述
@deepseek-ai/dsh-mcp-client插件的activeServerNames注册表存在生命周期泄漏。当会话关闭后创建新会话时,旧会话的 MCP 客户端实例没有被正确销毁,导致serverName仍然保留在全局的activeServerNamesWeakMap 中,阻止 agent preset 在新会话中加载。错误信息
复现步骤
~/.dsh/.agent-presets/work/agent.cordis.yml):serverName "context7" is already in use期望行为
关闭会话后,应该能立即创建新会话,不会报错。MCP 客户端实例应该在会话关闭时被正确销毁。
实际行为
activeServerNames注册表保留了已关闭会话的serverName条目,导致新会话无法加载同一个 agent preset。临时解决方案
activeServerNamesWeakMap)根因分析
在
packages/mcp/mcp-client/src/index.ts中:effect 清理函数
() => void names.delete(config.serverName)已注册但在会话关闭时未被调用。可能原因:ctx.root在不同会话之间发生变化,导致 WeakMap 查找失败环境信息
建议修复方案
方案1:在注册前检查并清理残留的旧注册:
方案2:确保会话关闭时 agent preset 插件的销毁被正确触发。
All reactions