Skip to content

fix(client): close EventSource when SSEClientTransport.start() fails - #3197

Open
tang-ontheway wants to merge 1 commit into
modelcontextprotocol:mainfrom
tang-ontheway:fix/sse-close-eventsource-on-start-error
Open

tang-ontheway wants to merge 1 commit into
modelcontextprotocol:mainfrom
tang-ontheway:fix/sse-close-eventsource-on-start-error

Conversation

@tang-ontheway

Copy link
Copy Markdown

Summary

When SSEClientTransport.start() (and thus Client.connect()) failed before receiving the endpoint event (e.g. connection refused, non-200 status, or failed 401 auth), _startOrAuth() rejected the promise without closing this._eventSource. As a result, EventSource remained open and kept reconnecting in the background, preventing processes from exiting and flooding onerror.

Changes

  • Close this._eventSource in _startOrAuth()'s onerror handlers when !this._endpoint (initial connection has not yet succeeded), matching the existing invalid-endpoint failure path while preserving automatic EventSource reconnection for errors that occur after start() has resolved.
  • Add unit test in packages/client/test/client/sse.test.ts verifying that EventSource stops reconnecting after start() rejects.

Verification

  • pnpm --filter @modelcontextprotocol/client test test/client/sse.test.ts (41 passed)
  • pnpm --filter @modelcontextprotocol/client exec tsc --noEmit (0 errors)
  • pnpm --filter @modelcontextprotocol/client lint & build (passed)

Fixes #3193

@tang-ontheway
tang-ontheway requested a review from a team as a code owner November 18, 2026 04:30
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: eaded0d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3197

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3197

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3197

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3197

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3197

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3197

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3197

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3197

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3197

commit: eaded0d

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSEClientTransport keeps reconnecting after Client.connect() rejects

1 participant