Azure / Microsoft.Azure.StackExchangeRedis

Azure-specific wrapper for the StackExchange.Redis client library
MIT License
17 stars 14 forks source link

ConfigureForAzureWithTokenCredentialAsync failed with ManagedIdentityCredential failed with SocketException after retries #58

Closed isacruzramos closed 1 month ago

isacruzramos commented 4 months ago

Hello,

We are in the process of rolling out Redis with AAD Authentication for our service. However, we started seeing SocketException failures when trying to establish a new connection:

Note: We are using DefaultAzureCredential() to authenticate and SDK version in 2.0.0

 await options.ConfigureForAzureWithTokenCredentialAsync(authToken.ObjectId, new DefaultAzureCredential());
 ConnectionMultiplexer multiplexer = await ConnectionMultiplexer.ConnectAsync(options).ConfigureAwait(false);

Connection failed with MI: **System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 10.0.5.9:2377** **07-10-2024 15:10:49**

Investigating this failure, we found that the token used to authenticate has an expiration date of: AccesTokenExpirationDate=7/11/2024 3:05:08 PM

This might correlate with the auth failure on 07/10 15:10PM, since the token expires every 24 hrs probably around that period of time the SDK was refreshing a new token and hence the failures during the connection attempt? However, my understanding is that Microsoft.Azure.StackExchangeRedis will refresh the token when 75% of the lifetime of the current token has passed.

The connection then succeded around 15:16PM: image

philon-msft commented 4 months ago

What version of the package are you on? You may need to upgrade to 3.1.0 to get this fix: #52

isacruzramos commented 4 months ago

What version of the package are you on? You may need to upgrade to 3.1.0 to get this fix: #52

version 2.0.0