{"record":{"id":"769958c6fc072196","repo":"dotnetcore/CAP","slug":"can-t-establish-redis-connection-after-attempt-attempts","errorCode":null,"errorMessage":"Can't establish redis connection,after [{attempt}] attempts.","messagePattern":"Can't establish redis connection,after \\[(.+?)\\] attempts\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.RedisStreams/IConnectionPool.LazyConnection.cs","lineNumber":56,"sourceCode":"\n            connection.LogEvents(logger);\n\n            if (!connection.IsConnected)\n            {\n                logger.LogWarning(\"Can't establish redis connection,trying to establish connection [attempt {attempt}].\", attempt);\n\n                await Task.Delay(TimeSpan.FromSeconds(2))\n                    .ConfigureAwait(false);\n\n                ++attempt;\n            }\n            else\n            {\n                attempt = 6;\n            }\n        }\n\n        if (connection == null) throw new Exception($\"Can't establish redis connection,after [{attempt}] attempts.\");\n\n        return new RedisConnection(connection);\n    }\n}\n\npublic class RedisConnection(IConnectionMultiplexer connection) : IDisposable\n{\n    private bool _isDisposed;\n    public IConnectionMultiplexer Connection { get; } = connection ?? throw new ArgumentNullException(nameof(connection));\n    public long ConnectionCapacity => Connection.GetCounters().TotalOutstanding;\n\n    public void Dispose()\n    {\n        Dispose(true);\n        GC.SuppressFinalize(this);\n    }\n\n    private void Dispose(bool disposing)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.RedisStreams/IConnectionPool.LazyConnection.cs#L38-L74","documentation":"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.","triggerScenarios":"Thrown at src/DotNetCore.CAP.RedisStreams/IConnectionPool.LazyConnection.cs:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the Redis connection string (host, port, password, SSL) in Configuration and that the server is reachable from the application host.","Test connectivity independently with redis-cli or StackExchange.Redis outside CAP to isolate network/firewall/DNS issues.","Increase server timeouts or check Redis server health (maxclients, memory) if connections are being dropped after handshake."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}