Skip to content

SignalR Redis backplane connection failure behavior explanation #20683

@jasonycw

Description

@jasonycw

We are using .NET Core 3.1 SignalR with Redis backplane running on AWS.
And sometime, our SignalR hub will throw the following error randomly

Failed to invoke hub method 'SignedIn'.
   StackExchange.Redis.RedisConnectionException: 
      No connection is available to service this operation: PUBLISH Project.Hub.SomeHub:connection:v3sGIq4zJfIHhEwnIUn26A; It was not possible to connect to the redis server(s). 
      To create a disconnected multiplexer, disable AbortOnConnectFail. 
      ConnectTimeout; IOCP: (Busy=0,Free=1000,Min=2,Max=1000), WORKER: (Busy=2,Free=32765,Min=2,Max=32767), Local-CPU: n/a
      ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). To create a disconnected multiplexer, disable AbortOnConnectFail. ConnectTimeout

I am not sure why there is these short connection issue between AWS serverS yet, but I saw there is some new update in the 3.1 doc about Custom behavior for connection failures
https://docs.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view=aspnetcore-3.1#custom-behavior-for-connection-failures

Can there be more explanation on what these codes do and mean, when and why are they needed?

And the example seems doesn't mention where to put "<your_Redis_connection_string>", I suppose it should be

services.AddSignalR()
        .AddMessagePackProtocol() // There is no such method for Microsoft.AspNetCore.SignalR 1.1.0
        .AddStackExchangeRedis(o =>
        {
            o.ConnectionFactory = async writer =>
            {
                var config = new ConfigurationOptions
                {
                    AbortOnConnectFail = false
                };
                config.EndPoints.Add("<your_Redis_connection_string>");

                // Explanation for the following?
                var connection = await ConnectionMultiplexer.ConnectAsync(config, writer);
                connection.ConnectionFailed += (_, e) =>
                {
                    Console.WriteLine("Connection to Redis failed."); // What if I want to use ILogger ?
                };

                if (!connection.IsConnected)
                {
                    Console.WriteLine("Did not connect to Redis."); // What if I want to use ILogger ?
                }

                return connection;
            };
        });

And according to https://gist.github.com/JonCole/36ba6f60c274e89014dd, I think setting AbortOnConnectFail to false is good enough?

public void ConfigureServices(IServiceCollection services) => services
            .AddSignalR(opts =>
            {
                opts.ClientTimeoutInterval = TimeSpan.FromMinutes(1);
                opts.KeepAliveInterval = TimeSpan.FromSeconds(30);
            })
            .AddStackExchangeRedis(Configuration.GetValue<string>("Cache"), opts =>
            {
                opts.Configuration.AbortOnConnectFail = false;
            }).Services

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions