Skip to content
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

aws-sdk's AbortSignal can't be given to Response #4582

Closed
3 tasks done
koSakano opened this issue Mar 27, 2023 · 8 comments
Closed
3 tasks done

aws-sdk's AbortSignal can't be given to Response #4582

koSakano opened this issue Mar 27, 2023 · 8 comments
Assignees
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. guidance General information and guidance, answers to FAQs, or recommended best practices/resources. p2 This is a standard priority issue workaround-available This issue has a work around available.

Comments

@koSakano
Copy link

Checkboxes for prior research

Describe the bug

The abortController.signal passed to client.send is internally passed to Respnose, but an error occurred in that area.

const abortController = new AbortController();
const client = new S3Client(clientParams);

const requestPromise = client.send(new CreateBucketCommand(commandParams), {
  abortSignal: abortController.signal,
});

SDK version number

@aws-sdk/[email protected] @aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Browser

Details of the browser/Node.js/ReactNative version

Chrome: 111.0.5563.110

Reproduction Steps

import { AbortController } from '@aws-sdk/abort-controller';

const controller = new AbortController();
// Type 'AbortSignal' is missing the following properties from type 'AbortSignal': reason, throwIfAborted, addEventListener,  removeEventListener, dispatchEvent
new Response(url, { signal: controller.signal });

const fetchRequest = new Request(url, requestOptions);

Observed Behavior

TypeError: Failed to construct 'Request': Failed to read the 'signal' property from 'RequestInit': Failed to convert value to 'AbortSignal'.

Expected Behavior

Works like a standard AbortController.

Possible Solution

No response

Additional Information/Context

No response

@koSakano koSakano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 27, 2023
@RanVaknin RanVaknin self-assigned this Mar 28, 2023
@RanVaknin
Copy link
Contributor

Hi @koSakano ,

Can confirm this is only happening after bundling for web.

@RanVaknin RanVaknin added needs-review This issue/pr needs review from an internal developer. p1 This is a high priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2023
@kuhe kuhe removed the needs-review This issue/pr needs review from an internal developer. label Mar 28, 2023
@kuhe kuhe self-assigned this Mar 28, 2023
@koSakano
Copy link
Author

@RanVaknin
Yes, I can confirm that it probably only happens after bundling for the web.
This did not happen with Node18.

@kuhe kuhe added p2 This is a standard priority issue and removed p1 This is a high priority issue labels Mar 29, 2023
@kuhe
Copy link
Contributor

kuhe commented Mar 29, 2023

For browsers, don't bundle the AbortController implementation from the @aws-sdk/abort-controller package.

Just use the browser's native AbortController, and it should be fine.

@kuhe kuhe added wontfix We have determined that we will not resolve the issue. workaround-available This issue has a work around available. guidance General information and guidance, answers to FAQs, or recommended best practices/resources. labels Mar 29, 2023
@koSakano
Copy link
Author

@kuhe
The browser's native AbortController is not available because it has a different type than the aws-sdk's AbortController.

// The browser's native AbortController
const abortController = new AbortController();
const client = new S3Client(clientParams);

const requestPromise = client.send(new CreateBucketCommand(commandParams), {
  // error occurred
  abortSignal: abortController.signal,
});

For example, in this case you will get the following error.

No overload matches this call.
  Overload 1 of 3, '(command: Command<ServiceInputTypes, PutObjectCommandInput, ServiceOutputTypes, PutObjectCommandOutput, SmithyResolvedConfiguration<...>>, options?: HttpHandlerOptions | undefined): Promise<...>', gave the following error.
    Type 'AbortSignal' is not assignable to type 'import(".../node_modules/@aws-sdk/types/dist-types/abort").AbortSignal'.
  Overload 2 of 3, '(command: Command<ServiceInputTypes, PutObjectCommandInput, ServiceOutputTypes, PutObjectCommandOutput, SmithyResolvedConfiguration<...>>, cb: (err: any, data?: PutObjectCommandOutput | undefined) => void): void', gave the following error.
    Argument of type '{ abortSignal: AbortSignal; }' is not assignable to parameter of type '(err: any, data?: PutObjectCommandOutput | undefined) => void'.
      Object literal may only specify known properties, and 'abortSignal' does not exist in type '(err: any, data?: PutObjectCommandOutput | undefined) => void'.

@kuhe
Copy link
Contributor

kuhe commented Mar 30, 2023

override the type error with abortController.signal as any, until a fix is made.

@kuhe
Copy link
Contributor

kuhe commented Mar 30, 2023

in #4591 I've loosened the type requirement such that this should no longer be a compilation error in future versions

@kuhe kuhe added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed wontfix We have determined that we will not resolve the issue. labels Mar 30, 2023
@koSakano
Copy link
Author

@kuhe
I've confirmed that the error no longer occurs in v.3.303.0. Thanks for the fix.

@kuhe kuhe closed this as completed Mar 31, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. guidance General information and guidance, answers to FAQs, or recommended best practices/resources. p2 This is a standard priority issue workaround-available This issue has a work around available.
Projects
None yet
Development

No branches or pull requests

3 participants