modelcontextprotocol / modelcontextprotocol/go-sdk
ClientSession.Subscribe can silently succeed while the session is closing
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 5.1k
- Forks
- 543
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 37
Description
Under the SEP-2575 path, ClientSession.Subscribe starts a subscriptions/listen request without awaiting the stream response. If the session has already started closing, or if Close races with Subscribe startup, Subscribe can return nil even though the listen stream was cancelled or rejected. In that case the local resourceSubs map can also keep an entry for a subscription that was never successfully started.
Reproduction:
- Connect a ClientSession with protocolVersion20260728.
- Close the session, or have Close start while Subscribe is entering the subscriptions/listen send path.
- Call Subscribe for a resource URI.
Expected:
Subscribe reports ErrConnectionClosed and does not leave a local resource subscription registered.
Actual:
Subscribe can report success or context cancellation without consistently rolling back the resource subscription entry.
Environment:
go version go1.26.5 darwin/arm64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ClientSession.Subscribe and the SEP-2575 subscriptions/listen send path, then inspect how Close and stream cancellation interact with the local resourceSubs map. Reproduce the closing race and verify that failed or cancelled startup returns ErrConnectionClosed and leaves no resource subscription registered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100