Potential race condition in (*mcp.ClientSession).Close()

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

メンテナーはふだん 1 日以内に返信

@blackwell-systems がすでに取り組んでいます。

2026年4月28日 から。

  • #913 @blackwell-systems による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
go
領域
backend

調査の方向性

まず gopls/internal/cmd/mcp_test.go の TestMCPCommandLogging 周辺と gopls/internal/cmd/mcp.go を確認し、その後 go test -run ^TestMCPCommandLogging$ -count=100 golang.org/x/tools/gopls/internal/cmd を実行して flake を再現します。MCP クライアントの終了と子プロセスの終了処理の相互作用を追跡します。繰り返し実行してもクライアント接続がエラーなしで閉じられれば完了です。

索引モデルが issue の本文から書いたものです。

説明

needs investigation P2

We've experienced an increasing number of test flakes in the tests for our MCP server. There is an error when closing the connection at the end of the tests: "server is closing: EOF". We think there might be a bug in mcp causing a race between the active part of Close (which breaks the connection and terminates the child process) and the waiting part of close (which seems to observe an error from the terminated child without realizing that close itself was responsible). Alan began tracing the issue here: https://github.com/golang/go/issues/77336#issuecomment-4090756198

To Reproduce
The test is here: https://github.com/golang/tools/blob/36360cdf844bb2553617bdc496c8d972c7229e7d/gopls/internal/cmd/mcp_test.go#L109
Server code is here: https://github.com/golang/tools/blob/master/gopls/internal/cmd/mcp.go
Try to reproduce the failure locally by using -count=100:

go test -run ^TestMCPCommandLogging$ -count=100 golang.org/x/tools/gopls/internal/cmd
=== RUN   TestMCPCommandLogging/trace.log
    gopls: server is closing: EOF
    mcp_test.go:156: closing MCP connection: exit status 2

Expected behavior
Client connection closes without error.

主要言語
Go
スター
5.4k
フォーク
623
平均マージ
22時間 10分
マージ済み PR(30日)
30

環境構築

Codespaces で開く

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

はじめの一歩

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

modelcontextprotocol/go-sdk のほかの issue

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

似ている issue

Go の issue をもっと見る

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

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