fix(protocol): add RequestAborted error code for AbortSignal cancellation#2177
Open
sakthiveltofficial wants to merge 1 commit into
Open
fix(protocol): add RequestAborted error code for AbortSignal cancellation#2177sakthiveltofficial wants to merge 1 commit into
sakthiveltofficial wants to merge 1 commit into
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@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.
Aborting a request via
AbortSignalproducedSdkErrorwith codeREQUEST_TIMEOUT— the same code as a genuine timeout — making itimpossible for callers to distinguish a deliberate cancellation from a
real timeout expiry.
Motivation and Context
The
cancel()closure insideProtocol._requestWithSchema()wrappedany non-
SdkErrorabort reason unconditionally asSdkErrorCode.RequestTimeout. When a caller does:the
DOMExceptionis not anSdkError, so it fell straight into thatgeneric fallback. The result was that user-initiated cancellations and
real timeouts were indistinguishable:
Fixes #2165
How Has This Been Tested?
packages/core/test/shared/protocol.test.ts:controller.abort(new DOMException('User cancelled', 'AbortError'))error.code === SdkErrorCode.RequestAbortederror.code !== SdkErrorCode.RequestTimeouttimeout: 0) continues to assertRequestTimeout, confirming the timeout path is unaffected.Breaking Changes
None.
RequestAbortedis a new enum member. No existing codechecks for it, and the timeout path (
SdkErrorCode.RequestTimeout)is completely unchanged — the timeout handler already passes a typed
SdkError(RequestTimeout, …)which hits theinstanceof SdkErrorbranch and is passed through unmodified.
Types of changes
Checklist
Additional context
Files changed (3, minimal diff):
packages/core/src/errors/sdkErrors.ts— added one enum member:packages/core/src/shared/protocol.ts— updatedcancel()closureto distinguish three cases instead of one:
packages/core/test/shared/protocol.test.ts— one new test coveringthe abort path.