fix: reject aborted requests with AbortSignal.reason#1886
Open
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
Open
fix: reject aborted requests with AbortSignal.reason#1886TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
TrevorBurnham wants to merge 1 commit intosmithy-lang:mainfrom
Conversation
When a request is aborted, the http handlers now use the AbortSignal's
reason property (if available) instead of always creating a generic
Error('Request aborted'). This lets callers using AbortSignal.any()
identify which signal caused the abort.
If reason is an Error instance, it is used directly. If it is a
non-Error value (e.g. a string), it is wrapped in an Error with
name 'AbortError'. If no reason is set, the existing behavior is
preserved with the default 'Request aborted' message.
Applied to all three handlers:
- NodeHttpHandler (http/https)
- NodeHttp2Handler (http2)
- FetchHttpHandler (fetch)
Fixes smithy-lang#1360
kuhe
reviewed
Feb 24, 2026
| /** | ||
| * Builds an abort error, using the AbortSignal's reason if available. | ||
| */ | ||
| function buildAbortError(abortSignal?: { reason?: unknown }): Error { |
Contributor
There was a problem hiding this comment.
should appear only once in this package
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.
Issue #, if available:
Fixes #1360
Description of changes:
When a request is aborted, all three HTTP handlers (
NodeHttpHandler,NodeHttp2Handler,FetchHttpHandler) reject with a genericnew Error("Request aborted"). This makes it impossible for callers to determine whichAbortSignalcaused the abort, especially when usingAbortSignal.any().The fix adds a
buildAbortErrorhelper to each handler that usesAbortSignal.reasonwhen available:reasonis anError, it is used directly (preserving the caller's error type and stack).reasonis a non-Error value (e.g. a string), it is wrapped in anErrorwithname: "AbortError".reasonis set (older runtimes or bare{ aborted: true }signals), the existing"Request aborted"behavior is preserved.All six abort sites across the three handlers were updated (two per handler: the early-abort check and the
onAbortlistener).Tests added to
node-http-handler.spec.ts:Errorreason directly"Request aborted"when no reason is setErrorwithname: "AbortError"By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.