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

Silently omit exception from Redis #16483

Closed
infofromca opened this issue Jul 24, 2024 · 14 comments
Closed

Silently omit exception from Redis #16483

infofromca opened this issue Jul 24, 2024 · 14 comments

Comments

@infofromca
Copy link
Contributor

infofromca commented Jul 24, 2024

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is.
Currently if the Redis is enabled and Redis server is not available, the whole site will fail in the beginning.

Describe the solution you'd like

A clear and concise description of what you want to happen.

it should not influence the whole site.

==========
An unhandled exception occurred while processing the request.
RedisConnectionException: It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.
StackExchange.Redis.ConnectionMultiplexer.ConnectImplAsync(ConfigurationOptions configuration, TextWriter writer, Nullable<ServerType> serverType) in ConnectionMultiplexer.cs, line 620

Stack Query Cookies Headers Routing
RedisConnectionException: It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.
StackExchange.Redis.ConnectionMultiplexer.ConnectImplAsync(ConfigurationOptions configuration, TextWriter writer, Nullable<ServerType> serverType) in ConnectionMultiplexer.cs
OrchardCore.Redis.Services.RedisDatabaseFactory+<>c__DisplayClass6_0+<<CreateAsync>b__0>d.MoveNext()
OrchardCore.Redis.Services.RedisService.ConnectAsync()
OrchardCore.Environment.Shell.Scope.ShellScope+<>c+<<ActivateShellInternalAsync>b__43_0>d.MoveNext()
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.ActivateShellInternalAsync()
OrchardCore.Environment.Shell.Scope.ShellScope.ActivateShellInternalAsync()
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func<ShellScope, Task> execute, bool activateShell)
OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Show raw exception details
StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImplAsync(ConfigurationOptions configuration, TextWriter writer, Nullable`1 serverType) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 620
   at OrchardCore.Redis.Services.RedisDatabaseFactory.<>c__DisplayClass6_0.<<CreateAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at OrchardCore.Redis.Services.RedisService.ConnectAsync()
   at OrchardCore.Environment.Shell.Scope.ShellScope.<>c.<<ActivateShellInternalAsync>b__43_0>d.MoveNext()
--- End of stack trace from previous location ---
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.ActivateShellInternalAsync()
   at OrchardCore.Environment.Shell.Scope.ShellScope.ActivateShellInternalAsync()
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func`2 execute, Boolean activateShell)
   at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
@hishamco
Copy link
Member

Please steps to reproduce

@infofromca
Copy link
Contributor Author

1--enable Redis feature
2--no redis server
3--got result
屏幕截图 2024-07-24 110705

@hishamco
Copy link
Member

2--no redis server

Redis Server should be running

@MikeAlhayek
Copy link
Member

It sounds like your Redis server is not reachable from your localhost

RedisConnectionException: It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.

@infofromca
Copy link
Contributor Author

infofromca commented Jul 24, 2024

the home page of the site did not call IRedisService or any other Redis stuff.
why even for home page , the site was down.
IMO, the pages which are not related with redis, should run well.
i guess it miss try catch on redis

@MikeAlhayek
Copy link
Member

I think if the Redis feature is enabled, it'll attempt to make a connection to the server which could be causing your issue. So I don't think you need to hit a page that uses IRedisService to encounter an issue with the connection string.

@infofromca
Copy link
Contributor Author

infofromca commented Jul 24, 2024

The pages which use db as data source should keep working as normal.
and the page use redis should fail as expected.
in this way, the whole site can run silently and smoothly in my view.

@MikeAlhayek
Copy link
Member

@infofromca

Based on what I can see, if you only enabled the Redis module, you should not get an exception. If the connection fails we log an error but we catch the exception so it should not break you app.

_factories.GetOrAdd(options.Configuration, new Lazy<Task<IDatabase>>(async () =>
{
try
{
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("Creating a new instance of '{name}'. A single instance per configuration should be created across tenants. Total instances prior creating is '{count}'.", nameof(ConnectionMultiplexer), _factories.Count);
}
return (await ConnectionMultiplexer.ConnectAsync(options.ConfigurationOptions)).GetDatabase();
}
catch (Exception e)
{
_logger.LogError(e, "Unable to connect to Redis.");
return null;
}
})).Value;

The error you shared, what that displayed on the UI or you got that from the logs? I expect it to be in the logs only but the UI should not break.

@infofromca
Copy link
Contributor Author

infofromca commented Jul 24, 2024 via email

@infofromca
Copy link
Contributor Author

infofromca commented Jul 24, 2024 via email

@infofromca
Copy link
Contributor Author

after double check , my home page use Article contentType which only includes those 4 parts :
Title Provides a Title for your content item.
Alias Provides a way to define custom aliases for content items.
Autoroute Provides a custom url for your content item.
HtmlBody Provides an HTML Body for your content item.

those 4 parts are not related with Redis I think.
but when I run the site, it hit redis stuff on the home page which cause the UI broken. reopen this issue.
屏幕截图 2024-07-24 175033

@infofromca
Copy link
Contributor Author

infofromca commented Jul 24, 2024

this is the code the home page hit:

private IDatabase? GetRedisDatabase()
{
    IDatabase? database = null;
    var redisService = _serviceProvider.GetService<IRedisService>();
    if (redisService != null)
    {
        database = redisService.Database;
    }

    return database;
}

@MikeAlhayek
Copy link
Member

@infofromca I think there is something invalid on your end (somewhere).

I can't reproduce this issue in OC. I created the a new tenant using the blog recipe. I then configured Redis with wrong credentials, enabled Redis and Redis Cache. When the app started I do see the error you encountered in my logs, but the UI did not break as expected since we catch the connection exception.

@infofromca
Copy link
Contributor Author

@MikeAlhayek Thanks, it happened on my custom layout. so close this

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

No branches or pull requests

3 participants