OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Prevent `ShellDescriptorManager` exception from bringing down the app

Open themattkenney opened this issue 6 years ago • 12 comments

On one of our Tenants, that is running SQL Lite we had a System.NullReferenceException causing the whole App Pool to lockup requiring an app pool restart.

We are looking into what caused the issue however I would expect an error on one tenant to not lockup the app pool.

Issue Details from app insights: image

Call Stack:

System.NullReferenceException:
   at YesSql.QueryExtensions.Query (YesSql.Abstractions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=51cdb8c1938e4789)
   at OrchardCore.Environment.Shell.Data.Descriptors.ShellDescriptorManager+<GetShellDescriptorAsync>d__8.MoveNext (OrchardCore.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullOrchardCore.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\orchardcore\src\OrchardCore\OrchardCore.Infrastructure\Shell\ShellDescriptorManager.csOrchardCore.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 52)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at OrchardCore.Environment.Shell.Builders.ShellContextFactory+<OrchardCore-Environment-Shell-Builders-IShellContextFactory-CreateShellContextAsync>d__5.MoveNext (OrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\orchardcore\src\OrchardCore\OrchardCore\Shell\Builders\ShellContextFactory.csOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 42)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at OrchardCore.Environment.Shell.ShellHost+<GetOrCreateShellContextAsync>d__12.MoveNext (OrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\orchardcore\src\OrchardCore\OrchardCore\Shell\ShellHost.csOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 87)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at OrchardCore.Environment.Shell.ShellHost+<GetScopeAsync>d__13.MoveNext (OrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\orchardcore\src\OrchardCore\OrchardCore\Shell\ShellHost.csOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 118)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at OrchardCore.Modules.ModularTenantContainerMiddleware+<Invoke>d__4.MoveNext (OrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.csOrchardCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 49)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__9.MoveNext (Microsoft.AspNetCore.Diagnostics, Version=3.1.8.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

themattkenney avatar Oct 09 '20 02:10 themattkenney

/cc @jtkech

hishamco avatar Oct 09 '20 15:10 hishamco

It might be an issue in ShellDescriptorManager. But ideally YesSql should have thrown an ArgumentException if the inputs were not valid. That would help.

sebastienros avatar Oct 09 '20 17:10 sebastienros

Update: We were able to figure out why we got the System.NullReferenceException. The issue was in the appsetting.json file, we removed all the unused tenants from our site but missed one tenant. This caused the 500 error when a bot called the site, we removed this tenant, and now no System.NullReferenceException.

@sebastienros if we wanted to block the error from crashing the app pool where would we start?

themattkenney avatar Oct 09 '20 21:10 themattkenney

I think you want to wait on @jtkech answer on that one 😄

Skrypt avatar Oct 09 '20 23:10 Skrypt

@themattkenney would be awesome to have just a little more details, to be able to repro. Like what to remove if we have two running tenants to get to this issue.

sebastienros avatar Oct 09 '20 23:10 sebastienros

I'd guess removing the tenant folder or simply the SQLite database while keeping the tenant config could potentially cause this issue? If not, then maybe the tenant that contains all the other tenants!

Skrypt avatar Oct 10 '20 00:10 Skrypt

@themattkenney

Maybe in GetShellDescriptorAsync(), add a try catch block around

_shellDescriptor = await _session.Query<ShellDescriptor>().FirstOrDefaultAsync();

So that it returns a null _shellDescriptor and then fallback to a MinimumShellDescriptor, but without failing.

Let us know if it fixes your issue

jtkech avatar Oct 10 '20 03:10 jtkech

We will give this a try! Thank you

themattkenney avatar Oct 10 '20 04:10 themattkenney

Can you share the result @themattkenney?

Piedone avatar May 15 '24 23:05 Piedone

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.

github-actions[bot] avatar Jun 18 '26 17:06 github-actions[bot]

Since this issue was opened more than five years ago and we have not encountered it again, I believe it has already been resolved. We can go ahead and close this issue.

mohit-naroliya avatar Jun 22 '26 12:06 mohit-naroliya

Thank you!

Piedone avatar Jun 22 '26 17:06 Piedone