OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.45k stars 2.41k forks source link

Do not attempt to connect to REDIS server during startup #16918

Open MikeAlhayek opened 1 month ago

MikeAlhayek commented 1 month ago

I have a recipe that enabled the Redis service for caching.

If you look at the following logs from setting up a new tenant called ww1

2024-10-21 09:42:52.0395|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Installing feature 'OrchardCore.Users.AuditTrail' 
2024-10-21 09:42:52.0395|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Installing feature 'TheAdmin' 
2024-10-21 09:42:52.0395|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.Data.Descriptors.ShellDescriptorManager|INFO|Updating shell descriptor for tenant 'ww1' ... 
2024-10-21 09:42:52.0395|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.Data.Descriptors.ShellDescriptorManager|INFO|Shell descriptor updated for tenant 'ww1'. 
2024-10-21 09:42:52.0499|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Recipes.Services.RecipeExecutor|INFO|Finished executing recipe step 'Feature'. 
2024-10-21 09:42:52.0499|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.Builders.ShellContextFactory|INFO|Creating shell context for tenant 'ww1' 
2024-10-21 09:42:53.2071|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Redis.Startup|ERROR|'Redis' features are not active on tenant 'ww1' as the 'Configuration' string is missing or invalid. System.ArgumentNullException: Value cannot be null. (Parameter 'configuration')
   at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 934
   at StackExchange.Redis.ConfigurationOptions.Parse(String configuration, Boolean ignoreUnknown) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 738
   at StackExchange.Redis.ConfigurationOptions.Parse(String configuration) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 728
   at OrchardCore.Redis.Startup.ConfigureServices(IServiceCollection services)    at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 934
   at StackExchange.Redis.ConfigurationOptions.Parse(String configuration, Boolean ignoreUnknown) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 738
   at StackExchange.Redis.ConfigurationOptions.Parse(String configuration) in /_/src/StackExchange.Redis/ConfigurationOptions.cs:line 728
   at OrchardCore.Redis.Startup.ConfigureServices(IServiceCollection services)
2024-10-21 09:42:53.7298|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Feature 'OrchardCore.Liquid' was installed 
2024-10-21 09:42:53.7298|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Feature 'OrchardCore.Settings' was installed 
2024-10-21 09:42:53.7298|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Feature 'OrchardCore.Contents' was installed 
2024-10-21 09:42:53.7298|ww1|00-e36bedfd9a47405eac3b9ae01241b28d-70574e8cbd5c7a6f-00||OrchardCore.Environment.Shell.ShellFeaturesManager|INFO|Feature 'OrchardCore.Title' was installed 

You'll notice a good time gap between installing the TheAdmin and OrchardCore.Liquid which is due to an error in the Redis during creating the shell context for tenant 'ww1'.

I have not spent time looking at the Redis implementation, but it sounds like we try to connect to the Redis server during startup "which is bad" validation the REDIS connection should be done asynchronously after the app is configured.

This is causing a long delay during setting the tenant using a tenant since we reload the shell after every recipe step or create multiple shell context when importing the startup recipe.

Ankur-Thakur-NEU commented 1 month ago

Hi @MikeAlhayek,

I'm new to the Orchard Core ecosystem and looking for a good first issue to work on. This issue caught my attention, and I wanted to ask if it would be a good one to take on as a beginner.

I have some experience with ASP.NET Core, but I'm still getting familiar with how multi-tenancy and Redis are integrated within Orchard Core. Could you please provide a bit more guidance on how I can replicate this issue? Specifically:

What Redis configuration/setup should I use to reproduce the problem? Are there any specific tenant configurations or startup recipes you used? Any advice on where to start looking in the codebase would also be really helpful. Thanks in advance! I’d love to contribute and help resolve this if it’s a good fit.

MikeAlhayek commented 1 month ago

@Ankur-Thakur-NEU glad you are looking to get involved! I am not sure this particular issue is one you want to take as your first issue info OC. But, you are free to give it a shot.

When you enabled Redis feature, this line will throw an exception if we are unable to parse the connection string https://github.com/OrchardCMS/OrchardCore/blob/1fb32873b0c85b7c4e82224cdbaf41ba714357c3/src/OrchardCore.Modules/OrchardCore.Redis/Startup.cs#L42 this isn't a problem here. I think there is something else that could be trying to establish the connection which causes the delay. I would look at other service that use services that depend on this feature to see if one of them attempts to open a connection or something around those lines.

Piedone commented 1 month ago

Other issues might be better suited for newcomers like you, see https://docs.orchardcore.net/en/latest/guides/contributing/contributing-code/#selecting-what-to-work-on

sebastienros commented 1 month ago

Repro

"Not connection to REDIS" might a solution but it doesn't describe the actual issue (pauses)

github-actions[bot] commented 1 month ago

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.