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

Enhanced retry strategies for Leaky Bucket and Retry policies #998

Merged
merged 10 commits into from Jan 18, 2024

Conversation

nozzlegear
Copy link
Owner

@nozzlegear nozzlegear commented Jan 18, 2024

This pull request adds small enhancements to the Leaky Bucket execution policy and the Retry execution policy to make them retry certain common request http request failures. I've based this code off of the retry policy found in Microsoft's Azure.Core SDK (MIT licensed), though it's not quite a one-to-one match since we don't have the concept of an HTTP pipeline in ShopifySharp.

These are the status codes that will be retried if a request fails in the Leaky Bucket and Retry execution policies:

case 408: // Request Timeout
case 429: // Too Many Requests
case 500: // Internal Server Error
case 502: // Bad Gateway
case 503: // Service Unavailable
case 504: // Gateway Timeout

The policy will retry these requests up to three times before throwing a ShopifyHttpException.

Importantly, the default behavior of the Leaky Bucket and Retry policies should remain intact -- they won't start retrying additional responses unless you opt-in to the behavior by using the new constructor overloads on each policy. I wanted to make this change available for testing and feedback right now, so I can gather some feedback on it.

Personally I think it makes sense to have this new behavior be the default, as having a 504 Gateway Timeout or 503 Service Unavailable break something instead of being retried is somewhat unexpected.

…etriable

Also adds several additional retriable status codes based on Microsoft's Azure.Core Retry Policy. Each non-rate-limit response will only be retried a maximum of 3 times per request before throwing an exception.
@nozzlegear nozzlegear merged commit 7eb12d3 into master Jan 18, 2024
@nozzlegear nozzlegear deleted the 503-retry branch January 18, 2024 08:00
@nozzlegear
Copy link
Owner Author

@clement911 I'm merging this now so I can get a beta build published to unblock some work I'm doing with a client, but would you mind reviewing these changes and letting me know your thoughts whenever you have spare time? No rush, it doesn't have to be soon!

@nozzlegear nozzlegear added this to the 6.12.0 milestone Jan 18, 2024
@clement911
Copy link
Collaborator

I think this is fine. I had a custom policy already doing something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants