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

Redis connection error restored #397

Open
fjluquerodriguez opened this issue Jun 3, 2021 · 15 comments
Open

Redis connection error restored #397

fjluquerodriguez opened this issue Jun 3, 2021 · 15 comments
Labels

Comments

@fjluquerodriguez
Copy link

fjluquerodriguez commented Jun 3, 2021

In a basic console app when DI resolves in constructor a error log raised: "Redis connection error restored."
It comes from ConnectionRestored in RedisCacheConnectionPoolManager.

DI config:

public static ServiceCollection RegisterCommonServices(this ServiceCollection services, RedisConfiguration redisConfiguration)
        {
            services.AddSingleton<ISerializer, NewtonsoftSerializer>();
            services.AddSingleton(redisConfiguration);
            services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
            services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();

            services.AddSingleton((provider) =>
            {
                return provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration();
            });
            return services;
        }

Config:

"Redis": {
    "Hosts": [
      {
        "Host": "127.0.0.1",
        "Port": "6379"
      }
    ], 
    "Database": 0,
    "ConnectTimeout": 60,
    "ConnectRetry": 2,
    "IdleTimeOutSecs": 120,
    "Ssl": false,
    "RequiresAuth": false,
    "NamespacePrefix": "",
    "PoolSize": 10,
    "MaxValueLength": 102400,
    "ConfigurationOptions": {
      "KeepAlive": 10,
      "ConnectTimeout": 30000,
      "ResponseTimeout": 60000,
      "AbortOnConnectFail": true,
      "AsyncTimeout": 15000,
      "SyncTimeout": 15000
    }

image

I've tried multiple combinations without luck. Despite this, if I try to read or write to redis it works fine... but this error is a bit confusing. I don't know if I can ignore it...

@ismkdc
Copy link
Contributor

ismkdc commented Jun 19, 2021

up i had same error

@ismkdc
Copy link
Contributor

ismkdc commented Jul 1, 2021

i still got the same error

@imperugo
Copy link
Owner

imperugo commented Jul 1, 2021

How do you use it? Because I use it in production without problem.
Also the code in this repo (see the example project) works fine.
Please download it and try it.

Thanks

@ismkdc
Copy link
Contributor

ismkdc commented Jul 1, 2021

//register redis
services.AddStackExchangeRedisExtensions(new RedisConfiguration
{
ConnectionString = Configuration.GetConnectionString("AriPlusRedis"),
PoolSize = 100,
ServerEnumerationStrategy = new ServerEnumerationStrategy
{
Mode = ServerEnumerationStrategy.ModeOptions.All,
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
}
});

in appsettings
"AriPlusRedis": "redis-master,redis-replica,password=xxx,abortConnect=false,connectTimeout=15000,allowAdmin=true"

@imperugo
Copy link
Owner

I can't see the serializer in your code, but I can see it here

https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/samples/StackExchange.Redis.Samples.Web.Mvc/Startup.cs#L42

That's the problem!

@ismkdc
Copy link
Contributor

ismkdc commented Jul 12, 2021

i updated my code but exception still throws :(

services.AddStackExchangeRedisExtensions(new RedisConfiguration
{
ConnectionString = Configuration.GetConnectionString("AriPlusRedis"),
PoolSize = 100,
ServerEnumerationStrategy = new ServerEnumerationStrategy
{
Mode = ServerEnumerationStrategy.ModeOptions.All,
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
}
});

@ismkdc
Copy link
Contributor

ismkdc commented Jul 12, 2021

debian@ns3100181:~/ariplus-backend$ docker-compose -f docker-compose.yml logs web
Attaching to ariplus-backend_web_2, ariplus-backend_web_1, ariplus-backend_web_4, ariplus-backend_web_3
web_1 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
web_1 | Redis connection error restored.
web_4 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
web_4 | Redis connection error restored.
web_4 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0]
web_4 | Redis connection error restored.

@ismkdc
Copy link
Contributor

ismkdc commented Jul 22, 2021

I have removed PoolSize parameter but problem still continue

@ismkdc
Copy link
Contributor

ismkdc commented Jul 22, 2021

I have using totally same conf with sample but problem still continue

//register redis
var conf = new RedisConfiguration
{
AbortOnConnectFail = true,
Password = Configuration.GetValue("RedisConf:Password"),
Hosts = Configuration.GetSection("RedisConf:Hosts").Get<RedisHost[]>(),
AllowAdmin = true,
ConnectTimeout = 6000,
Database = 0,
PoolSize = 50,
ServerEnumerationStrategy = new ServerEnumerationStrategy
{
Mode = ServerEnumerationStrategy.ModeOptions.All,
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw
}
};

        services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(conf);

@kirillito
Copy link

I'm getting the same error in my production logs. Digging deeper into sources for both StackExchange.Redis.Extensions and StackExchange.Redis , the error is logged when Redis connection is recovered from previous failure.

Strange enough, I don't see any mention of previous errors in my logs, and no other signs of crashing. My question here is: why is this event logged here as error? Why not warning, since it is a recovery event, not actual failure?

            private void ConnectionRestored(object sender, ConnectionFailedEventArgs e)
            {
                logger.LogError("Redis connection error restored.");
            }

@ahmb
Copy link

ahmb commented Sep 28, 2021

Same issue for me. It does not appear if its its executed the first time, but after shut down and re-connection it begins to display this error

@ibrahimuludag
Copy link

I have the same logs. It happens when I deploy the application only. I agree with @kirillito. I believe this should be logged as a warning.

@sprudel79
Copy link

sprudel79 commented Nov 4, 2021

I had the same issue in my setup. In my ASP.NET Core service I am using DataProtection and of course I would like to use Redis to store the Keys.
At first I used the following code:

services
    .AddDataProtection()
    .SetDefaultKeyLifetime(TimeSpan.FromDays(keyLifeTime))
    .PersistKeysToStackExchangeRedis(() => 
    {
        var sp = services.BuildServiceProvider();
        var redisCacheConnectionPoolManager = sp.GetService<IRedisCacheConnectionPoolManager>(); 
        return redisCacheConnectionPoolManager.GetConnection().GetDatabase(); 
    }
    , key)
    .UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
    {
    EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
    ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
    });

I have recognized that the "Redis connection error restored" error was printed when I was trying to get the IDatabase instance directly via the RedisCacheConnectionPoolManager.

Then I have changed the section like this:

services
    .AddDataProtection()
    .SetDefaultKeyLifetime(TimeSpan.FromDays(keyLifeTime))
    .PersistKeysToStackExchangeRedis(() => 
    {
        var sp = services.BuildServiceProvider();
        var redisClient = sp.GetService<IRedisCacheClient>();
        return redisClient.GetDbFromConfiguration().Database;
    }
    , key)
    .UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
    {
    EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
    ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
    });

Now I am getting a RedisClient from the managed Redis connection pool to retrieve the IDatabase instance and the error was gone.

@GlodenBoy
Copy link

Also have this bug, in V7 version.

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

No branches or pull requests

8 participants