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

未關閉
#855 3 則留言 1 個 reaction 已指派 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 來重現這個間歇性故障。追蹤 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 分鐘
30 天內合併 PR
30

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/go-sdk 的其他 Issue

查看 modelcontextprotocol/go-sdk 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。