Skip to content

Unable to connect to Redis due to authentication - ConnectionFailureType #1879

@sagimar

Description

@sagimar

Hi,

In case the connection with Redis failed due to authentication failure (e.g. password is configured incorrectly due to key rotation),
the ConnectionFailureType that is returned is ConnectionFailureType.UnableToConnect.

My suggestion is in this case to return ConnectionFailureType.AuthenticationFailure
Thus, me as a client, can decide to disconnect Redis and retry with a new primary key that I have fetched.

The automatically retry mechanism of IMultiplexer would never success to connect with its own retry policy, but I don't want to catch any RedisConnectionException.

Is there any reason that the function returns ConnectionFailureType.UnableToConnect instead of ConnectionFailureType.AuthenticationFailure in this case?

internal static Exception UnableToConnect(ConnectionMultiplexer muxer, string failureMessage=null)
{
var sb = new StringBuilder("It was not possible to connect to the redis server(s).");
if (muxer != null)
{
if (muxer.AuthSuspect) sb.Append(" There was an authentication failure; check that passwords (or client certificates) are configured correctly.");
else if (muxer.RawConfig.AbortOnConnectFail) sb.Append(" Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.");
}
if (!string.IsNullOrWhiteSpace(failureMessage)) sb.Append(' ').Append(failureMessage.Trim());
return new RedisConnectionException(ConnectionFailureType.UnableToConnect, sb.ToString());
}

Thanks,
Sagi

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions