Redis ConnectionMultiplexer firing multiple ConnectionFailed after dispose

770 Views Asked by At

We are using the StackExchange.Redis ConnectionMultiplexer class as follows:

 private void InitializeConnection()
    {
        _logger.Info("Initializing a connection to the Redis cluster. ");
        bool isReconnectionAttempt = false;

        if (_connectionMultiplexer != null)
        {
            Debug.WriteLine("disposing " + _connectionMultiplexer.GetHashCode());
            _connectionMultiplexer.ConnectionFailed -= HandleConnectionFailedEvent;

            // test this change.....
            _connectionMultiplexer.Close();
            isReconnectionAttempt = true;
            _logger.Info("This is reconnection attempt to the Redis cluster.");
        }

        _connectionMultiplexer = ConnectionMultiplexer.Connect(_connectionString);
        _needConnect = !_connectionMultiplexer.IsConnected;
        _connectionMultiplexer.ConnectionFailed += HandleConnectionFailedEvent;

When I simulate a network issue, the ConnectionFailed event is fired as expected. When this happens, we attempt to dispose the object and create a new one. However, even after the previous _connectionMultiplexer instance was closed/disposed, we still get several ConnectionFailed events fired by the previous instance.

The document, however, indicates that we only get a single ConnectionFailed event when the network goes down. The next time we get such an event is when the network goes down again. But this is not what I am experiencing. Ideas?

0

There are 0 best solutions below