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

Offen
#855 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@blackwell-systems arbeitet bereits daran.

Seit 28.4.2026.

  • #913 von @blackwell-systems — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
75/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Ruhig
Tech-Stack
go
Bereich
backend

Rechercherichtung

Beginne mit gopls/internal/cmd/mcp_test.go rund um TestMCPCommandLogging und gopls/internal/cmd/mcp.go und führe dann go test -run ^TestMCPCommandLogging$ -count=100 golang.org/x/tools/gopls/internal/cmd aus, um den Flake zu reproduzieren. Verfolge das Zusammenspiel zwischen dem Schließen des MCP-Clients und der Beendigung des Kindprozesses; abgeschlossen ist die Aufgabe, wenn die Clientverbindung über wiederholte Durchläufe hinweg ohne Fehler geschlossen wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Go
Sterne
5.4k
Forks
623
Ø Merge
22 Std. 10 Min.
Gemergte PRs (30 T.)
30

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/go-sdk

Alle Issues in modelcontextprotocol/go-sdk

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.