Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectTimeout exception was throw when use new ConfigurationOptions #2840

Open
pikadun opened this issue Jan 20, 2025 · 1 comment
Open

Comments

@pikadun
Copy link

pikadun commented Jan 20, 2025

But if I use ConfigurationOptions.Parse, everything works fine.

StackExchange.Redis.RedisConnectionException: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=EVAL, timeout: 5000, inst: 0, qu: 0, qs: 0, aw: False, bw: CheckingForTimeout, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 1, serverEndpoint: localhost:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: Auth.Web, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=2,Max=32767), POOL: (Threads=3,QueuedItems=0,CompletedItems=54,Timers=2), v: 2.7.27.49176 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
public static IServiceCollection AddCaching(this IServiceCollection services, IConfiguration configuration)
{
    services.AddStackExchangeRedisCache(options =>
    {

        var config = configuration.GetRedisConfiguration();
        var a = new ConfigurationOptions
        {
            ClientName = config.ClientName,
            DefaultDatabase = config.DefaultDatabase,
            EndPoints = new EndPointCollection([.. config.EndPoints.Cast<EndPoint>()])
        };
        var b = ConfigurationOptions.Parse(a.ToString());
        // Timeout when use a;
        options.ConfigurationOptions = a;
        // Worked when use b;
        // options.ConfigurationOptions = b;
    });

    return services;
}
@NickCraver
Copy link
Collaborator

To answer this, we'd need to know what connection string is being parsed. They fundamentally take the same path under the covers so we are likely to see some difference in the parsed connection string. Based on your symptoms, I would assume that the endpoints are not being passed correctly to option a here and we time ever connecting. If you pass a string logger to the .Connect()/.ConnectAsync() methods, you can see a full connect log for what's going wrong which may make things more apparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants