fix(client): allow transport restart after close()#1828
Open
felixweinberger wants to merge 1 commit intomainfrom
Open
fix(client): allow transport restart after close()#1828felixweinberger wants to merge 1 commit intomainfrom
felixweinberger wants to merge 1 commit intomainfrom
Conversation
StreamableHTTPClientTransport: change start() guard from 'controller exists' to 'controller exists and not aborted', allowing restart after close(). Also clear _sessionId in close() so the stale server-assigned ID is not sent on post-restart requests. SSEClientTransport: clear _eventSource, _endpoint, _abortController in close() so start()'s guard allows restart. Fixes #1641
🦋 Changeset detectedLatest commit: db137d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Allows
StreamableHTTPClientTransportandSSEClientTransportto restart afterclose().Motivation and Context
Fixes #1641.
start()throws"already started"afterclose()because the start guard checks whether_abortControllerexists, not whether it was aborted. This breaks OAuth re-authentication flows: start → 401 → close → OAuth → start (throws).StreamableHTTPClientTransport: Changed the
start()guard fromif (this._abortController)toif (this._abortController && !this._abortController.signal.aborted). This is safer than clearing_abortControllerinclose(), which would break thesignal.abortedchecks at :344, :437, :456 used by late-firing reconnection callbacks. Also clears_sessionIdinclose()so the stale server-assigned ID is not sent on post-restart requests (would 404).SSEClientTransport: Clears
_eventSource,_endpoint,_abortControllerinclose(). SSE's start guard checks_eventSource, and there are nosignal.aborteddependencies.How Has This Been Tested?
Added a test that receives a session ID, closes, restarts, and asserts both
start()succeeds and the stale session ID is not sent. Test fails on main (expected 'stale-session-abc' to be undefined), passes with the fix. All 347 client tests pass.Breaking Changes
None.
Types of changes
Checklist
Additional context
Credit to @matantsach for #1647 which identified the issue and the SSE state-reset approach.