dotnetcore/CAP · error · Exception

Can't establish redis connection,after

Error message

Can't establish redis connection,after [{attempt}] attempts.

What it means

A generic guard thrown at the end of the Redis Streams connection-pool retry loop: after the configured number of reconnect attempts (default 6, spaced 2 seconds apart) the underlying connection still reports IsConnected == false, so connection is unusable and ConnectAsync aborts. The root cause is the Redis server being unreachable or refusing the client (wrong host/port, auth failure, timeouts), not this code path.

Solutions

  1. Verify the Redis connection string (host, port, password, SSL) in Configuration and that the server is reachable from the application host.
  2. Test connectivity independently with redis-cli or StackExchange.Redis outside CAP to isolate network/firewall/DNS issues.
  3. Increase server timeouts or check Redis server health (maxclients, memory) if connections are being dropped after handshake.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at src/DotNetCore.CAP.RedisStreams/IConnectionPool.LazyConnection.cs:56 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14). Data as JSON: /api/errors/769958c6fc072196. Report an issue: GitHub.

Appendix: source

Thrown at src/DotNetCore.CAP.RedisStreams/IConnectionPool.LazyConnection.cs:56

            connection.LogEvents(logger);

            if (!connection.IsConnected)
            {
                logger.LogWarning("Can't establish redis connection,trying to establish connection [attempt {attempt}].", attempt);

                await Task.Delay(TimeSpan.FromSeconds(2))
                    .ConfigureAwait(false);

                ++attempt;
            }
            else
            {
                attempt = 6;
            }
        }

        if (connection == null) throw new Exception($"Can't establish redis connection,after [{attempt}] attempts.");

        return new RedisConnection(connection);
    }
}

public class RedisConnection(IConnectionMultiplexer connection) : IDisposable
{
    private bool _isDisposed;
    public IConnectionMultiplexer Connection { get; } = connection ?? throw new ArgumentNullException(nameof(connection));
    public long ConnectionCapacity => Connection.GetCounters().TotalOutstanding;

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    private void Dispose(bool disposing)

View on GitHub (pinned to e52b8508e5)