-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Amplify REST requests should not automatically retry on serverside errors #13093
Comments
Hi @severi Thank you for raising this issue. ![]() We'll bring this to the team's attention and see how we can address it, whether it be through changing the behavior or exposing a way to disable this behavior. |
any updates for this |
I'm picturing a badly-coded server that is starting to fail when it gets overloaded. Arbitrarily tripling the number of requests sent to it really doesn't seem helpful. |
I am using TanStack Query and would like to use its retrying system rather than amplify's. |
Checking to see if there has been an update on this bug? |
I see there was a PR opened a couple weeks ago. Any updates/movement on that? |
Any update on this issue? I see a PR for this issue has been open for 3 months now: #13641 |
Would love an update here on PR #13641! |
Hi @severi @the03ennis @chris-xylem This is a valid feature request. Currently the API category does not expose options to control the retry behavior. However the mentioned PR would bring undesired side-effect to AWS service clients that need this behavior. We just noticed this because it was labeled with GraphQL label which does not share the same visibility. As an workaround, if you want full control of request lifecycle, you can create your own handler without using the REST API handler. For example, in react query, you can provide your own query function. You can access the aws credentials with |
This seems more like a bug then a feature request to me as this behavior was not present v5 |
This is absolutely a bug, this kind of behaviour should not be enforced. At the very least it should be configured as a default that can be overriden by a config. With respect, why is this taking so long? Especially given there's been an open pull request with a fix for 6 months. |
@chris-xylem and @lehotskysamuel, appreciate the feedback here and I'll bring this issue and associated PR in front of the team again for review. |
For anyone following this issue, wanted to let you all know that this issue was reviewed again and we agree that this need to be updated to a bug (rather than feature request). There is no documented change in our migration guides going from v5 to v6 that details this behavior. As for the associated PR #13641, we'll close that out since we want to handle the implementation of this internally. Thank you, @daixi98 for opening it and attempting to resolve this. |
Thank you @cwomack for reviewing this and pushing this 🙏. |
Hello everyone, we have been looking into a way to disable this retry behavior for these APIs. One reason we did not simply merge the PR referenced above is because we felt strongly that it was important not to simply turn off the behavior across the board for all developers using Amplify V6 but instead offer a way to opt out of the current behavior. To that end we are proposing to add a
The change proposed will look something like the following: import { get } from 'aws-amplify/api';
get({
apiName: 'myRestApi',
path: 'path',
retryStrategy: { strategy 'no-retry' }
}); Where the retryStrategy type would look like the following: export type RetryStrategy =
| {
// Default strategy and current behavior in V6.
// No actions will be required from developers who prefer this retry model.
strategy: 'default';
}
| {
// Disables retries.
strategy: 'no-retry';
} Tagging folks who have participated in this thread to see if this solution would be viable to move forward with. Thank you all! |
Folks, the default strategy should be set to 'no-retry'. I understand why you want to maintain the same behavior and set the 'default' strategy to be as is, but the "as is" behavior is not supposed to be this way and is a bug in my opinion. Those who need the retry automatically, should opt-in and modify the strategy. Otherwise, by default, no retries and no need to override the strategy to get the desired behavior. |
While I agree this should be categorized as a bug and the default behavior needs to change, I also understand the Amplify team's concerns about backwards compatibility for existing users. Just fixing this bug in v6 is probably too risky for what it would do to systems in the wild. I would suggest that you roll ahead with the plan @cshfang has outlined above, but I'd also strongly suggest that you plan to change the default behavior in your next version. The decision to generically retry failed calls like this should never be made by the underlying framework. Kudos for wanting to make things easier for people, but this misguided feature never should have been built in the first place, and you should deprecate it as soon as it is safe to do so. |
I agree with both comments above. Personally I'd prefer the no retry to be the default but I understand backwards compatibility issues, so Eric's suggestion to deprecate and remove in the next version bump is a good middle ground. I have one feedback about the suggested API - why make RetryStrategy an object? I'd prefer a string or enum. Maybe that was your plan and it was just pseudo code, then ignore my comment :) . |
As others have said, I agree that the default should be But all in all, I like the suggested fix and appreciate the work being done to resolve this issue. |
Thank you for this thoughtful feedback. The rationale for making this an object stems from a bit of ambition about how we can further extend this. Imagine, if you will, some kind of future state where it is possible to have other kinds of retry strategies which exposed various other configurations alongside the strategy. For example, perhaps being able to configure the number of retries a la retryStrategy: {
strategy: 'default',
retryAttempts: 30 // not recommended 😅
} As many of you have mentioned, for now, we want to make sure to address the immediate need of disabling retries on these REST APIs altogether and we will revisit this and consider flipping the default behavior in a major version bump. |
Before opening, please confirm:
JavaScript Framework
Not applicable
Amplify APIs
REST API
Amplify Version
v6
Amplify Categories
api
Backend
None
Environment information
Describe the bug
Amplify should never automatically try to retry API requests if they fail on serverside errors (500, 502, 503, 504)
https://github.com/aws-amplify/amplify-js/blob/main/packages/core/src/clients/middleware/retry/defaultRetryDecider.ts#L26C4-L26C21
This behaviour is just plain wrong and should not exists OR at the very least should be possible to be disabled
Expected behavior
Api request fails once and is not retryed
Reproduction steps
server responds with error code 500, amplify post request automatically retries 2 times after the failed attempt
Code Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: