Skip to content

Orchard Core can cause dependency resolution problems due to use of async code in non-async context #17547

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

Closed
jimitndiaye opened this issue Mar 3, 2025 · 13 comments · Fixed by #17798
Labels
Milestone

Comments

@jimitndiaye
Copy link

Describe the bug

I've been experiencing request timeouts caused by what seemed to be dependency injection problems but turned out to be a result of executing async code within OrcardCore as synchronous. Specifically, in OrchardCore.DynamicCache.CacheOptionsConfiguration.Configure:

        switch (_siteService.GetSiteSettingsAsync().GetAwaiter().GetResult()
            .CacheMode)
        {
             // ... other code
        }

This is resulting in blocking when resolving types like IContentManager.

I originally posted this in the OrchardCore discord but was advised to raise this issue on Github.

Orchard Core version

2.1.6

To Reproduce

I don't have isolated code to reproduce it but this is a blazor server app and I have a service registered with AddScoped that has IContentManager and ISession as dependencies. This issue doesn't happen 100% of the time but it happens fairly often, especially on the first request to the hosting page after startup.

Expected behavior

IContentManager and ISession should be resolved consistently without blocking.

Logs and screenshots

Debugging in Visual studio with Just-my-code disabled revealed the following:

Image

The origin is this line here:

Image

@Piedone
Copy link
Member

Piedone commented Mar 5, 2025

The root of this is options not supporting async: dotnet/runtime#97575. However, perhaps we can work around this with our IAsyncConfigureOptions<TOptions>. Also see: #15165

@sebastienros
Copy link
Member

Waiting on lock owned by Thread ...

Could you where this thread is at? That could help understand why it's blocked? It should not be because of the async call.

@jimitndiaye
Copy link
Author

jimitndiaye commented Mar 12, 2025

I'm not sure if it is related but I often see the following error in the logs:

System.ArgumentNullException: Value cannot be null. (Parameter 'provider')
   at System.ThrowHelper.Throw(String paramName)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at OrchardCore.Documents.DocumentManager`1.get_DocumentStore()
   at OrchardCore.Documents.DocumentManager`1.GetOrCreateImmutableAsync(Func`1 factoryAsync)
   at OrchardCore.ContentManagement.ContentDefinitionManager.GetTypeDefinitionAsync(String name)
   at OrchardCore.ContentManagement.Handlers.ContentPartHandlerCoordinator.InvokeHandlers[TContext,TFieldContext](TContext context, TFieldContext fieldContext, Func`4 partHandlerAction, Func`4 fieldHandlerAction, Boolean createPartIfNotExists, Boolean createFieldIfNotExists)
   at OrchardCore.Modules.InvokeExtensions.InvokeAsync[TEvents,T1](IEnumerable`1 events, Func`3 dispatch, T1 arg1, ILogger logger)

Copy link
Contributor

It seems that this issue didn't really move for quite a while despite us asking the author for further feedback. Is this something you'd like to revisit any time soon or should we close? Please reply.

@github-actions github-actions bot added the stale label Mar 28, 2025
@jimitndiaye
Copy link
Author

Just noticed that this is "waiting for author feedback". I thought I'd already provided as much information as I could.

@github-actions github-actions bot removed the stale label Mar 28, 2025
@sebastienros
Copy link
Member

Would you be able to try the latest preview release? We fixed some bugs in the database layer.

Also, could you rephase the problem? I am not finding what problem you are actually facing, like an exception, or the app is not responding ... It seems you only shared logs without symptoms.

@jimitndiaye
Copy link
Author

The original problem was that dependency injection of ISession and IContentManager would result in request time-outs. It doesn't happen 100% of the time but it would happen intermittently, particularly on the first request after startup. The screenshots above depict one such occasion.

Copy link
Contributor

It seems that this issue didn't really move for quite a while despite us asking the author for further feedback. Is this something you'd like to revisit any time soon or should we close? Please reply.

Copy link
Contributor

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.

@jimitndiaye
Copy link
Author

Great news!

@sebastienros
Copy link
Member

@jimitndiaye I am not very optimistic that the change would be solving your issue, but I may be wrong. I'd love if you could try it and tell us if that changed anything.

@jimitndiaye
Copy link
Author

@jimitndiaye I am not very optimistic that the change would be solving your issue, but I may be wrong. I'd love if you could try it and tell us if that changed anything.

Is it released? Or would I need to switch to the preview releases?

@gvkries
Copy link
Contributor

gvkries commented Apr 30, 2025

It's currently in preview only, I'm not sure if it is possible to easily back port to 2.x.

/cc @MikeAlhayek What do you think?

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

Successfully merging a pull request may close this issue.

4 participants