Skip to content

Fix double onerror trigger on client.close() (Streamable HTTP) #880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anil567849
Copy link

Summary

This PR fixes an issue where onerror was being triggered twice when
client.close() was executed.
The duplicate call originated from _startOrAuthSse, where an extra
this.onerror?.(error as Error); invocation existed in the catch block.

Since the method already throws the error, the extra onerror call was redundant
and caused duplicate event firing.

Motivation and Context

Fixes #868
When client.close() was executed, onerror was being triggered twice.
This happened because _startOrAuthSse had an extra this.onerror?.(error as Error); inside its catch block, even though the error was already propagated via throw error;.
By removing this line, the onerror event now fires only once, matching expected behavior.

How Has This Been Tested?

Ran the provided reproduction script from Issue #868.
Verified that after the change, the output contains only one error: The operation was aborted. log.
Confirmed no side effects or missing error propagation in other scenarios.

Breaking Changes

No breaking changes — this only removes redundant error event firing.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

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

@Anil567849 Anil567849 requested a review from a team as a code owner August 15, 2025 20:11
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