mcp: a canceled write on IOTransport/StdioTransport cannot leave the write queue
维护者通常 1 天内回复
@Tangerg 已经在做这个了。
开始于 2026年11月5日。
评估
这个 Issue 还没有评估数据。
描述
Checklist
- I searched the existing issues, and this has not been reported before.
- This is a real problem that I ran into myself, using the latest release of the SDK.
- I ran into it in a production system, not in a toy example, a benchmark, or an automated or AI-driven scan of the code.
- I (a human) examined the relevant SDK code, and wrote or reviewed every line of this report. It is not unreviewed AI output.
- This report is brief and concise, and sticks to the facts needed to understand the problem.
What happened?
ioConn.Write checks the context only before taking its write mutex. If a write is blocked because the peer stopped reading, another Write whose context is canceled keeps waiting for the mutex instead of returning, and the blocked write itself cannot be interrupted by canceling its context. Callers that bound a request or notification with a deadline therefore hang until the peer reads again.
Expected: a write that has not started returns ctx.Err() without sending anything, and canceling the write in progress stops it (closing the connection, since a partial frame cannot be withdrawn).
AI assistance: the investigation was done with Claude; I reviewed the report and the SDK code.
How to reproduce
package main
import (
"context"
"fmt"
"net"
"time"
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
local, peer := net.Pipe() // the peer never reads, as with a stalled server
defer peer.Close()
conn, err := (&mcp.IOTransport{Reader: local, Writer: local}).Connect(context.Background())
if err != nil {
panic(err)
}
write := func(name string, timeout time.Duration) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
done := make(chan error, 1)
go func() { done <- conn.Write(ctx, &jsonrpc.Request{Method: name}) }()
select {
case err := <-done:
fmt.Printf("%s: returned %v\n", name, err)
case <-time.After(timeout + 2*time.Second):
fmt.Printf("%s: still blocked 2s after its %v deadline\n", name, timeout)
}
}
go write("active", 200*time.Millisecond)
time.Sleep(50 * time.Millisecond)
write("queued", 100*time.Millisecond)
time.Sleep(time.Second)
}
Output with v1.8.0:
queued: still blocked 2s after its 100ms deadline
active: still blocked 2s after its 200ms deadline
Where did you hit this?
Frame hosts MCP plugin processes over stdio; when a plugin stopped reading, shutdown hung on pending writes, so Frame had to wrap SDK writes in its own cancelable layer.
Go MCP SDK version
v1.8.0 (also on main at f91620f)
Go version
go version go1.27.3 darwin/arm64
Logs
No response
- 主要语言
- Go
- 星标
- 5.3k
- 派生
- 607
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 81
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/go-sdk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/go-sdk#1512 ·
维护者通常 1 天内回复
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensions可能重新可做 关联的 PR 已关闭且未合并。 未关闭needs investigation
难度 2/5 1-3 小时 新手友好度 72/100
modelcontextprotocol/go-sdk#745 · 13 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
modelcontextprotocol/go-sdk#1506 · 2 条评论 ·
维护者通常 1 天内回复
-
mcp: closing a session right after a cancelled call drops notifications/cancelled, so the server handler keeps running可能已有人在做 @vshalpnjabi 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
modelcontextprotocol/go-sdk#1505 · 1 条评论 ·
维护者通常 1 天内回复
-
mcp: list_changed can only be broadcast; a server cannot notify one session (2026-07-28 subscriptions/listen)可能已有人在做 @nahapetyan-serob 于 1 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 32/100
modelcontextprotocol/go-sdk#1480 · 1 条评论 · 已指派 2 人 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/go-sdk 的全部 Issue
相似的 Issue
-
bug os:ios
难度 2/5 1-3 小时 新手友好度 72/100
hajimehoshi/ebiten#4039 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 69/100
open-telemetry/opentelemetry-go-compile-instrumentation#1713 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
JakeChampion/lang#14392 ·
维护者通常 1 天内回复
-
agent-butler-finding bug
难度 1/5 1-3 小时 新手友好度 84/100
jordansmall/spindrift#6557 ·
维护者通常 1 天内回复