Skip to content

fix(client): fire onerror only once when the standalone GET stream fails - #2418

Open
pablopupo wants to merge 1 commit into
modelcontextprotocol:mainfrom
pablopupo:fix/868-double-onerror-on-close
Open

fix(client): fire onerror only once when the standalone GET stream fails#2418
pablopupo wants to merge 1 commit into
modelcontextprotocol:mainfrom
pablopupo:fix/868-double-onerror-on-close

Conversation

@pablopupo

@pablopupo pablopupo commented Jul 2, 2026

Copy link
Copy Markdown

Ports #880 to v2, following the maintainer request in #868. Fixes #868.

Motivation and Context

_startOrAuthSse reported a failure through onerror and then rethrew it. The standalone GET and reconnection call sites caught that same rejection and reported it again, so one stream failure could produce two callbacks.

The helper now only propagates failures. Each call site that owns a stream reports the failure once. resumeStream() keeps its existing contract: the returned promise rejects and onerror is called once. The 401/403 authentication retry path continues to return through the recursive call without taking error ownership.

How Has This Been Tested?

Four event-driven regressions cover:

  • a failed standalone GET;
  • close() aborting an in-flight standalone GET;
  • resumeStream() rejection plus one onerror callback;
  • a failed resumption GET started by _send.

The focused transport tests pass with 73 tests. The full client suite passes with 801 tests, and the repository's non-e2e package matrix, check:all, build:all, documentation build, distribution type smoke test, and changeset check also pass.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@pablopupo
pablopupo requested a review from a team as a code owner July 2, 2026 14:19
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c4ad5e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core-internal Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: c4ad5e3

@pablopupo
pablopupo force-pushed the fix/868-double-onerror-on-close branch from 1d9dea4 to c4ad5e3 Compare August 4, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When executing client.close(), onerror will be executed twice (Streamable HTTP)

1 participant