Skip to content

fix(mcp-server): optimize session validation to prevent 2-second time#3106

Merged
hengyunabc merged 1 commit intoalibaba:masterfrom
Yeaury:fix/mcp-session-validation-timeout
Dec 25, 2025
Merged

fix(mcp-server): optimize session validation to prevent 2-second time#3106
hengyunabc merged 1 commit intoalibaba:masterfrom
Yeaury:fix/mcp-session-validation-timeout

Conversation

@Yeaury
Copy link
Contributor

@Yeaury Yeaury commented Dec 19, 2025

问题描述

在使用 Cherry Studio 作为客户端连接 arthas-mcp-server 时,出现了严重的延迟问题:

  • 每个请求(特别是 ping 请求)都会延迟约 2 秒
  • 客户端经常收到超时错误:notifications/cancelled with reason "Request timed out"
  • 问题在 mcp-inspector 中不会出现,仅在 Cherry Studio 中出现

根本原因

通过日志分析发现,问题出在 ArthasCommandSessionManager.isSessionValid() 方法中:

  • 该方法使用 commandExecutor.pullResults() 来验证 session 是否有效
  • pullResults() 是一个长轮询设计,当没有结果时会等待最多 2 秒(ResultConsumerImpl.pollTimeLimit = 2000ms
  • 对于 ping 等简单请求,由于没有新的命令结果,会触发完整的 2 秒等待
  • 这导致每个请求都有 2 秒的延迟,Cherry Studio 的请求超时时间较短,因此频繁超时

…out delays

Previously, session validation used pullResults() which would block for up to 2 seconds when no results were available, causing Cherry Studio and other clients to timeout.

Changes:
- Replace blocking pullResults() validation with time-based expiry check (25 min threshold)
- Add lastAccessTime tracking to CommandSessionBinding for efficient validation
@hengyunabc hengyunabc added this to the 4.1.4 milestone Dec 25, 2025
@hengyunabc hengyunabc merged commit b99147d into alibaba:master Dec 25, 2025
13 checks passed
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.

2 participants