fix(mcp): serialize keepalive probes with RPC calls - #64989
Conversation
Duplicate of #62811 — same mechanism: guards the MCP |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Looks Good
- Fix(mcp): serialize keepalive probes with RPC calls
- 45 additions, 2 deletions — targeted fix
- No issues detected
Reviewed by Hermes Agent
|
Closing this duplicate in favor of a follow-up PR based on #62811. #62811 covers the keepalive/active-RPC serialization race. The follow-up adds transport-aware recovery for empty-message ClosedResourceError/BrokenPipeError failures observed after the stdio session closes, plus regression coverage. Follow-up will preserve this PR's _rpc_lock serialization and target the same MCP failure class. |
Summary
Serialize MCP keepalive RPCs with the per-server
_rpc_lockused by normal tool calls.Problem
MCPServerTask._keepalive_probe()sentpingand thelist_toolsfallback without acquiring the lock. On stateful JSON-RPC transports, a keepalive request could therefore race an in-flighttools/callresponse and corrupt the stream, causing false keepalive failures and reconnects.Fix
session.send_ping()with_rpc_lock.session.list_tools()fallback with_rpc_lock.Validation
tests/tools/test_mcp_tool.py: 214 passedpy_compile: passedgit diff --check: passedScope
This is a targeted serialization fix. Existing reconnect, circuit-breaker, and optional-ping fallback behavior is unchanged.