Skip to content

Disable MSAL's internal retry#48472

Open
anannya03 wants to merge 2 commits intoAzure:mainfrom
anannya03:disable-msal-retry
Open

Disable MSAL's internal retry#48472
anannya03 wants to merge 2 commits intoAzure:mainfrom
anannya03:disable-msal-retry

Conversation

@anannya03
Copy link
Member

@anannya03 anannya03 commented Mar 19, 2026

Description

Disable MSAL's internal retries and use its own for ConfientialClient (.e.g ClientSecretCredential), Public Client and Managed Identity.

Fixes #47765

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings March 19, 2026 05:59
@anannya03 anannya03 requested review from a team, g2vinay and joshfree as code owners March 19, 2026 05:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR disables MSAL4J’s internal retry behavior for identity flows that use ConfidentialClientApplication, PublicClientApplication, and ManagedIdentityApplication, aiming to rely on Azure SDK retry policies instead (per issue #47765).

Changes:

  • Call disableInternalRetries() on MSAL application builders for confidential, public, and managed identity flows.
  • Add unit tests validating observed HTTP request count matches Azure-core retry settings (i.e., no extra MSAL retries).
  • Document the change in azure-identity’s changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientBase.java Disables MSAL internal retries for confidential/public/managed identity MSAL builders.
sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java Adds tests that assert total HTTP requests equals configured retry attempts + initial call.
sdk/identity/azure-identity/CHANGELOG.md Adds a Bugs Fixed entry describing MSAL internal retry disablement.

StepVerifier.create(client.authenticateWithUsernamePassword(request, "test-username", "test-password"))
.expectErrorMatches(e -> e instanceof ClientAuthenticationException).verify();

assertEquals(RETRY_COUNT + 1, requestCount.get(), "With maxRetries=" + RETRY_COUNT + ", total requests should be " + (RETRY_COUNT + 1) + " (1 initial + " + RETRY_COUNT + " retries)");
.identityClientOptions(options)
.build();

StepVerifier.create(client.authenticateWithManagedIdentityMsalClient(new TokenRequestContext().addScopes("https://management.azure.com/.default")))
Comment on lines 239 to +242
applicationBuilder = applicationBuilder.logPii(options.isUnsafeSupportLoggingEnabled())
.authority(authorityUrl)
.instanceDiscovery(options.isInstanceDiscoveryEnabled());
.instanceDiscovery(options.isInstanceDiscoveryEnabled())
.disableInternalRetries();
Comment on lines 311 to +314
builder = builder.logPii(options.isUnsafeSupportLoggingEnabled())
.authority(authorityUrl)
.instanceDiscovery(options.isInstanceDiscoveryEnabled());
.instanceDiscovery(options.isInstanceDiscoveryEnabled())
.disableInternalRetries();
Comment on lines +413 to +415
ManagedIdentityApplication.Builder miBuilder = ManagedIdentityApplication.builder(managedIdentityId)
.logPii(options.isUnsafeSupportLoggingEnabled())
.disableInternalRetries();

### Bugs Fixed

- Disabled MSAL's internal retry for Confidential Client, Managed Identity and Public Client Applications.
StepVerifier.create(client.authenticateWithConfidentialClient(request))
.expectErrorMatches(e -> e instanceof MsalServiceException).verify();

assertEquals(RETRY_COUNT + 1, requestCount.get(), "With maxRetries=" + RETRY_COUNT + ", total requests should be " + (RETRY_COUNT + 1) + " (1 initial + " + RETRY_COUNT + " retries)");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

Disable MSAL retries for Confidential Client and Public Client

2 participants