Fix double onerror trigger on client.close() (Streamable HTTP) #880
+1
−2
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.
Summary
This PR fixes an issue where
onerror
was being triggered twice whenclient.close()
was executed.The duplicate call originated from
_startOrAuthSse
, where an extrathis.onerror?.(error as Error);
invocation existed in thecatch
block.Since the method already throws the error, the extra
onerror
call was redundantand 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
Checklist