-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
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.
- ID: c548355c-d88f-b941-0622-56732973123b
- Version Independent ID: bddd7575-422d-4342-af48-f6b0979fb69a
- Content: Redis backplane for ASP.NET Core SignalR scale-out
- Content Source: aspnetcore/signalr/redis-backplane.md
- Product: aspnet-core
- Technology: aspnetcore-signalr
- GitHub Login: @bradygaster
- Microsoft Alias: bradyg