ConnectionRestored event always raised two times after Redis restart
We use StackExchange.Redis in SignalR Redis scale-out, I found that ConnectionRestored event always raised two times after Redis restart.
Here is simple repro app:
private static ConnectionMultiplexer _connection;
static void Main(string[] args)
{
string connectionString = "......";
_connection = ConnectionMultiplexer.Connect(connectionString);
_connection.ConnectionRestored += OnConnectionRestored;
Console.ReadLine();
}
private static void OnConnectionRestored(object sender, ConnectionFailedEventArgs args)
{
Console.WriteLine("_connection.IsConnected is " + _connection.IsConnected);
}
Repro steps: 1). Update connectionString for your Redis, build the app and run 2). Stop and Restart the Redis
Expected result: OnConnectionRestored rasie one time, in output should just display one line "_connection.IsConnected is ..."
Actual result: OnConnectionRestored rasie two times, in output displays two lines "_connection.IsConnected is ..."
At a guess, you'll probably find from the ConnectionFailedEventArgs object that one event is for the Interactive connection, and the other for the Subscription connection (assuming you are using pub/sub functionality in Redis).
Try changing your console printing line to:
Console.WriteLine("{0}: _connection.IsConnected is {1}", args.ConnectionType, _connection.IsConnected);
Yep, the above comment is correct. Closing this out due to answered and age.