Skip to content

Bug: Sentinel connection with AbortOnConnectFail=false fails to return multiplexer and leaks objects on startup failure #2980

@stevestock

Description

@stevestock

Version: StackExchange.Redis 2.9.32

Description:

When calling ConnectionMultiplexer.ConnectAsync() with Sentinel configuration & AbortOnConnectFail = false, if sentinels are unavailable at startup:

  1. Library creates a Sentinel ConnectionMultiplexer internally (via SentinelConnectAsync())
  2. Defaults to ServerType.Standalone
  3. Calls GetSentinelMasterConnection() which throws: RedisConnectionException: "Sentinel: The ConnectionMultiplexer is not a Sentinel connection. Detected as: Standalone"
  4. Never returns the ConnectionMultiplexer - making it inaccessible to caller
  5. Leaks the ConnectionMultiplexer - when LoggerFactory is 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.

Related Issues: #2173, #2649, #2808, #2893

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions