-
Notifications
You must be signed in to change notification settings - Fork 88
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
Implemented Retry Policy #521
base: andyohart/managed-identity
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a spec for this feature? It seems very basic e.g. no backoff, hardcoded retry count and delay. Blockers are
- implicit upgrade to Go 1.21
- cancellation
- rewinding request bodies
if attempts-1 < 1 { | ||
return resp, nil | ||
} | ||
time.Sleep(delay) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSAL must observe Context cancellation while waiting to retry. See for example the Azure SDK retry policy
return resp, nil | ||
} | ||
time.Sleep(delay) | ||
return retry(attempts-1, delay, c, req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to rewind the request body before retrying (this will matter for Cloud Shell). Make sure you have a test verifying retries have the same content as the initial attempt
Added test to check request body is same for each request.
It is very basic retry, and has a fix 1 second between retry and max count of 3 retries |
defer tryCancel() | ||
cloneReq := req.Clone(tryCtx) | ||
resp, err = c.Do(cloneReq) | ||
if err == nil && !contains(retryStatusCodes, resp.StatusCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should consider the Source. retryStatusCodes
follows IMDS docs, and that guidance doesn't make sense for other APIs. For example, in general you don't want to retry 404. Azure SDK retries these codes by default and special-cases IMDS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @neha-bhargava as this is probably a small bug in all other MSALs (which should not affect Azure SDK)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussions with @bgavrilMS, we have decided to maintain consistency with other MSAL implementations. We will create a bug report to address this issue and ensure that the necessary updates are applied across all relevant areas.
Updating the error code for retry
Quality Gate passedIssues Measures |
Pull Request: Implement Retry Policy for Client
Overview
This pull request introduces a retry policy for network calls in the client. The retry policy aims to enhance the resilience of our application by allowing it to automatically retry failed requests up to a maximum of three times.
Changes Made
Retry Policy Implementation:
Configuration Option to Disable Retry Policy:
WithRetryPolicyDisabled()
for the client.Default Behavior (Retries Enabled)
By default, the client will automatically retry failed requests up to 3 times with delay of 1 second. Here’s how to create the client with the retry policy enabled:
Default Behavior (Retries Disabled)
By default, the client will not retry the failed request. Here’s how to create the client with the retry policy disabled:
Error List when retry is done.