Refactor retry logic and add special behavior for IMDS#960
Merged
Avery-Dunn merged 11 commits intodevfrom Jun 5, 2025
Merged
Conversation
Robbie-Microsoft
requested changes
May 30, 2025
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java
Outdated
Show resolved
Hide resolved
This was referenced Jun 4, 2025
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultRetryPolicy.java
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/HttpHelper.java
Outdated
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityRetryPolicy.java
Show resolved
Hide resolved
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/DefaultRetryPolicy.java
Show resolved
Hide resolved
Robbie-Microsoft
approved these changes
Jun 4, 2025
Consistently use constants for HTTP status codes
bgavrilMS
reviewed
Jun 5, 2025
| @@ -0,0 +1,25 @@ | |||
| package com.microsoft.aad.msal4j; | |||
Member
There was a problem hiding this comment.
suggestion: All this HTTP and Retry files should go into a folder of their own?
Contributor
Author
There was a problem hiding this comment.
I agree that it would be good to group similar files together, but currently all of the source files are just in one big folder. I don't know why it was originally designed that way (the people who would did it are no longer here), and I've always felt it was a bad practice.
I've created an issue to track a refactor of the directory structure, at the very least there's quick value in properly organizing the non-public classes: #965
Add API to disable internal retry behavior
Robbie-Microsoft
approved these changes
Jun 5, 2025
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.
This PR refactors HTTP retry logic by splitting it into classes that implement a new interface, similar to what was done in MSAL Node and .NET:
AzureAD/microsoft-authentication-library-for-js#7614
AzureAD/microsoft-authentication-library-for-dotnet#5231
The following changes were made:
IRetryPolicyinterface, defining methods to determine if a certain HTTP response should be retried, the number of retries to perform, and how long to wait between retriesIRetryPolicy:IMDSRetryPolicy, for behavior specific to IMDSManagedIdentityRetryPolicy, for all other managed identity scenariosDefaultRetryPolicy, for all other scenariosFor testing:
RequestThrottlingTestandManagedIdentityTests.managedIdentityTest_Retry()IMDSRetryPolicybased on status codes, which is now covered by the new unit test inManagedIdentityTestsMost of the "files changed" list in this PR are due to changes in two other PRs:
#960
#964