Getting error: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry

Dairion, Jonathan 20 Reputation points
2024-08-19T15:56:45.7366667+00:00

Hello everyone,

I have got the following code that generate a Token to get access to ChatGPT

 Protected Function GetAccessToken(scope As TokenRequestContext, c As CancellationToken) As AccessToken
   Dim Credential As ClientSecretCredential
   Dim CredentialOption As ClientSecretCredentialOptions
   Dim RequestContexts As String() = {"api://xxxxxxxxxxxxxxxxxx/.default"}


   If GecoConfig.IsUATEnvironment Then
     Credential = New ClientSecretCredential(m_AZURE_TENANT_ID, m_UATClientID, m_UATClientSecret)
   Else
     Credential = New ClientSecretCredential(m_AZURE_TENANT_ID, m_ProdClientID, m_ProdClientSecret)
   End If

   m_Token = Credential.GetToken(New TokenRequestContext(RequestContexts), c)

   Return m_Token
 End Function

The code works in my environment. However in our UAT it works but only for 1 of the application. The UAT web application is ok but not the web application version that has the version we have deployed in production (it does not work in production too).

I am getting the following error message

Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy.

I have tried to add the following code but it did not help

    Dim CredentialOption As New ClientSecretCredentialOptions
      CredentialOption.Retry.MaxRetries = 10 ' Increase this value to retry more times before failing
      CredentialOption.Retry.Delay = TimeSpan.FromSeconds(2) ' This is the minimum delay between retries
      CredentialOption.Retry.MaxDelay = TimeSpan.FromSeconds(10) ' This is the maximum delay between retries
      CredentialOption.Retry.Mode = RetryMode.Exponential ' This will increase the delay between retries exponentially

      Credential = New ClientSecretCredential(m_AZURE_TENANT_ID, m_UATClientID, m_UATClientSecret, CredentialOption)

Any idea? Could it our firewall that could block the scope?

Thanks in advance, Jonathan

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,890 questions
{count} votes

Accepted answer
  1. YutongTie-MSFT 52,596 Reputation points
    2024-08-19T17:37:47.0233333+00:00

    Hello @Dairion, Jonathan

    Dairion just confirmed that this issue has gone.

    For others who has the similar issue, it seems there is a connection issue, please share a entire error message so that we know which step the error happened.

    To solve the issue in general -

    Scope Configuration: Verify that the scope (api://xxxxxxxxxxxxxxxxxx/.default) is correctly configured and valid for your application. The scope should match what your API expects.

    Check the firewall settings: Make sure that the firewall setting are configured correctly. Ensure that your firewall rules are not blocking the requests to the Azure AD endpoints. Both UAT and production environments need to be able to reach Azure AD services.

    Verify Connectivity: Check if there are any network issues or restrictions that might be affecting connectivity to Azure services.

    Verify Application: Ensure that the ClientSecretCredentialOptions is correctly applied and used by the ClientSecretCredential instance.

    Check the retry policy: The error message suggests that the retry policy is failing after 4 tries. You can adjust the retry policy in the ClientOptions.Retry property. You can also configure a custom retry policy in the ClientOptions.RetryPolicy property.

    Please take a look and have a try, let us know the detailed error message if you have.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.