Skip to content

Commit 072a160

Browse files
committed
PR feedback
1 parent 2dc552a commit 072a160

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSRetryPolicy.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
package com.microsoft.aad.msal4j;
55

6+
import java.util.Arrays;
7+
import java.util.Collections;
8+
import java.util.HashSet;
9+
import java.util.Set;
10+
611
//IMDS uses a different try policy than other MI flows, see https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/docs/imds_retry_based_on_errors.md
712
class IMDSRetryPolicy extends ManagedIdentityRetryPolicy {
813
private static final int LINEAR_RETRY_NUM = 7;
@@ -12,17 +17,22 @@ class IMDSRetryPolicy extends ManagedIdentityRetryPolicy {
1217

1318
private int currentRetryCount;
1419
private int lastStatusCode;
15-
20+
21+
private static final Set<Integer> RETRYABLE_STATUS_CODES = Collections.unmodifiableSet(
22+
new HashSet<>(Arrays.asList(
23+
HttpStatus.NOT_FOUND.getCode(),
24+
HttpStatus.REQUEST_TIMEOUT.getCode(),
25+
HttpStatus.GONE.getCode(),
26+
HttpStatus.TOO_MANY_REQUESTS.getCode()
27+
))
28+
);
29+
1630
@Override
1731
public boolean isRetryable(IHttpResponse httpResponse) {
1832
currentRetryCount++;
1933
lastStatusCode = httpResponse.statusCode();
2034

21-
return HttpStatus.isServerError(lastStatusCode) ||
22-
lastStatusCode == HttpStatus.NOT_FOUND.getCode() ||
23-
lastStatusCode == HttpStatus.REQUEST_TIMEOUT.getCode() ||
24-
lastStatusCode == HttpStatus.GONE.getCode() ||
25-
lastStatusCode == HttpStatus.TOO_MANY_REQUESTS.getCode();
35+
return HttpStatus.isServerError(lastStatusCode) || RETRYABLE_STATUS_CODES.contains(lastStatusCode);
2636
}
2737

2838
@Override

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityRetryPolicy.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,32 @@
33

44
package com.microsoft.aad.msal4j;
55

6+
import java.util.Arrays;
7+
import java.util.Collections;
8+
import java.util.HashSet;
9+
import java.util.Set;
10+
611
/**
712
* Retry policy for most Managed Identity scenarios
813
*/
914
class ManagedIdentityRetryPolicy implements IRetryPolicy {
1015
private static final int RETRY_NUM = 3;
1116
private static int RETRY_DELAY_MS = 1000;
1217

18+
private static final Set<Integer> RETRYABLE_STATUS_CODES = Collections.unmodifiableSet(
19+
new HashSet<>(Arrays.asList(
20+
HttpStatus.NOT_FOUND.getCode(),
21+
HttpStatus.REQUEST_TIMEOUT.getCode(),
22+
HttpStatus.TOO_MANY_REQUESTS.getCode(),
23+
HttpStatus.INTERNAL_SERVER_ERROR.getCode(),
24+
HttpStatus.SERVICE_UNAVAILABLE.getCode(),
25+
HttpStatus.GATEWAY_TIMEOUT.getCode()
26+
))
27+
);
28+
1329
@Override
1430
public boolean isRetryable(IHttpResponse httpResponse) {
15-
int statusCode = httpResponse.statusCode();
16-
17-
return statusCode == HttpStatus.NOT_FOUND.getCode() ||
18-
statusCode == HttpStatus.REQUEST_TIMEOUT.getCode() ||
19-
statusCode == HttpStatus.TOO_MANY_REQUESTS.getCode() ||
20-
statusCode == HttpStatus.INTERNAL_SERVER_ERROR.getCode() ||
21-
statusCode == HttpStatus.SERVICE_UNAVAILABLE.getCode() ||
22-
statusCode == HttpStatus.GATEWAY_TIMEOUT.getCode();
31+
return RETRYABLE_STATUS_CODES.contains(httpResponse.statusCode());
2332
}
2433

2534
@Override

0 commit comments

Comments
 (0)