-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Version: StackExchange.Redis 2.9.32
Description:
When calling ConnectionMultiplexer.ConnectAsync() with Sentinel configuration & AbortOnConnectFail = false, if sentinels are unavailable at startup:
- Library creates a Sentinel
ConnectionMultiplexerinternally (viaSentinelConnectAsync()) - Defaults to
ServerType.Standalone - Calls
GetSentinelMasterConnection()which throws:RedisConnectionException: "Sentinel: The ConnectionMultiplexer is not a Sentinel connection. Detected as: Standalone" - Never returns the ConnectionMultiplexer - making it inaccessible to caller
- Leaks the ConnectionMultiplexer - when
LoggerFactoryis attached, logs continue being written from the orphaned multiplexer showing ongoing retry attempts
Reproduction:
var options = new ConfigurationOptions
{
EndPoints = { "sentinel1:26379", "sentinel2:26379", "sentinel3:26379" },
ServiceName = "mymaster",
AbortOnConnectFail = false,
LoggerFactory = myLoggerFactory
};
// Start application BEFORE Redis/Sentinel servers are running
var multiplexer = await ConnectionMultiplexer.ConnectAsync(options);
// Throws exception but multiplexer continues retrying in background (leaked)Expected Behavior:
With AbortOnConnectFail = false, ConnectAsync() should return the ConnectionMultiplexer even when initial connection fails, allowing event handler registration and automatic reconnection.
Actual Behavior:
- Exception thrown, no multiplexer returned
- Multiplexer created internally but inaccessible (leaked)
- Manual retry loop required, likely creating additional leaked objects on each attempt
Why This Bug Matters
Redis Sentinel is the actively maintained, official solution for high availability in non-clustered deployments. This bug prevents proper usage of StackExchange.Redis with standard Redis HA deployments, particularly in orchestrated environments (Kubernetes, Docker Compose) where applications commonly start before dependencies.