mcp: a canceled write on IOTransport/StdioTransport cannot leave the write queue

オープン
#1,498 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 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日 11時間
マージ済み PR(30日)
82

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/go-sdk のほかの issue

modelcontextprotocol/go-sdk の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。