Repository navigation
mcp: retire an ended listen when UnsubscribeHandler fails - #1558
Merged
guglielmo-san merged 2 commits intoDec 1, 2026
Merged
Conversation
nahapetyan-serob
requested review from
guglielmo-san
and
a balanced review from Copilot
November 30, 2026 13:58
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to clean up ended resource subscriptions.
No open issues 🎉
What changed in this PR
Fixes stale resource subscriptions in the Go MCP SDK by retiring ended listens even when UnsubscribeHandler fails, addressing #1545.
Changes:
- Removes ended listen registrations and logs handler errors while preserving the handler’s ability to reject explicit unsubscribe requests.
- Gives teardown handlers a non-cancelled context with a five-second deadline.
- Adds regression tests for registration cleanup, handler context, and legacy unsubscribe behavior.
| File | Description |
|---|---|
mcp/server.go |
Updates listen cleanup, error logging, and teardown context handling. |
mcp/mcp_test.go |
Tests modern listen cleanup and legacy unsubscribe rejection when the handler fails. |
Review effort: Balanced
guglielmo-san
approved these changes
Dec 1, 2026
guglielmo-san
deleted the
serob/retire-ended-listen-when-UnsubscribeHandler-fails
branch
December 1, 2026 09:12
Tangerg
added a commit
to Tangerg/go-sdk
that referenced
this pull request
Dec 2, 2026
Brings the fork up to upstream main at 723d70e, which is v1.9.0 plus fourteen later commits. Upstream changes: modelcontextprotocol#1238, modelcontextprotocol#1511, modelcontextprotocol#1515, modelcontextprotocol#1517, modelcontextprotocol#1521, modelcontextprotocol#1523, modelcontextprotocol#1524, modelcontextprotocol#1527, modelcontextprotocol#1533, modelcontextprotocol#1537, modelcontextprotocol#1539, modelcontextprotocol#1540, modelcontextprotocol#1544, modelcontextprotocol#1547, modelcontextprotocol#1549, modelcontextprotocol#1550, modelcontextprotocol#1553, modelcontextprotocol#1554, modelcontextprotocol#1558, modelcontextprotocol#1560, modelcontextprotocol#1561, modelcontextprotocol#1562. Fork-side adaptations: - internal/jsonrpc2: the -32600 reply to a duplicate in-flight ID (modelcontextprotocol#1550) is written off the read loop and holds its admission slot until written, like every other reply under MaxIncomingRequests. - mcp: ClientSession.initialize takes the session state lock that upstream added, and still projects the negotiated version to the connection. - mcp: the fork's copies of hintomitempty, nowrapinvalidparams and nomethodnotfoundcodeinerror go away with upstream's removal (modelcontextprotocol#1533). - extensions/skills: reads the protocol version from the fork's json.RawMessage Meta. - Tests: the duplicate-ID admission test drains the new reply, and the client cancellation test runs on 2025-11-25 only, because 2026-07-28 clients reject every standalone server request (modelcontextprotocol#1537, modelcontextprotocol#1540, modelcontextprotocol#1554).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
subscriptions/listenends, its deferredendSubscriptioncall ranUnsubscribeHandlerwith the listen's already-cancelled context and returnedon the handler's error before removing the registration. A handler returning
ctx.Err()was enough to leave the listen registered, soResourceUpdatedkept notifying it and stale entries accumulated across subscribe/unsubscribe
cycles until the session disconnected.
Changes:
logged at debug level, since no one is waiting for it. An explicit
resources/unsubscribecan still be refused by the handler.UnsubscribeHandlernow gets a non-cancelled context(
context.WithoutCancel) bounded by a 5s timeout, so context-aware cleanupcan run. This changes what handlers receive on that path
Fixes #1545