OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

Lifetime scope error when enabling/disabling modules in multiple tenants in parallel #2409

Closed orchardbot closed 9 years ago

orchardbot commented 12 years ago

@pszmyd created: https://orchard.codeplex.com/workitem/18582

I've just ran into this error, when tried to enable/disable a given module on 6 tenants at once.

Server Error in '/' Application.

Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.

Source Error:

Line 19: **/ Line 20: Line 21: Func<dynamic, dynamic> Zone = x => Display(x); // Zone as an alias for Display to help make it obvious when we're displaying zones Line 22: Line 23: / Inserting some ad hoc shapes

Source File: c:\inetpub\wwwroot\KS Gateway Pages\Themes\TheAdmin\Views\Layout.cshtml Line: 21

Stack Trace:

[ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.] Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +407 Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.<>cDisplayClass4.b3(DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:55 Orchard.DisplayManagement.Descriptors.<>cDisplayClass5.b2(DisplayContext displayContext) in c:\Work\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55 Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:179 Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:88 Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in c:\Work\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:71

orchardbot commented 12 years ago

@pszmyd commented:

It's happening randomly, though. You might have to try a couple of times (eg. enabling some module with a couple of dependencies, so the enabling process would take a bit longer) to repro.

orchardbot commented 12 years ago

kdnmih commented:

I have same problem. I install the orchard cms on Local IIS(windows 7).

orchardbot commented 12 years ago

@bleroy commented:

@kdnmih: you may be getting the same error message but it may not be the same problem.

orchardbot commented 12 years ago

@bleroy commented:

@kdnmih: if you have VS11 installed, you will have to either uninstall it or update ORchard to the latest in the 1.x branch. Orchard 1.4 is not compatible with VS11 Beta.

orchardbot commented 12 years ago

scharada commented:

it is happening to me too.

i am not running it from VS (i have both installed 10 and 11)

it seems to be happening everytime i open multiple pages of the site at the same time which was not happening before this last update.

could autofac be the issue ? look at this link : http://stackoverflow.com/questions/9340828/autofac-with-asp-net-webforms-instances-cannot-be-resolved-and-nested-lifetimes

orchardbot commented 12 years ago

Levitikon commented:

Could you explain how you're enabling a module for multiple tenants at once? I've been struggling with a quick way to enable modules for 50 some odd tenants. I came up with a batch file to do this:

call bin\Orchard.exe feature enable Contrib.RewriteRules /t:mysite1 call bin\Orchard.exe feature enable Contrib.RewriteRules /t:mysite2

But when I run this on a machine that's also running orchard in IIS with an active application pool, I run into the same error you described.

orchardbot commented 12 years ago

consigliory commented:

I have the same issue. Is there any work around it?

orchardbot commented 12 years ago

@Piedone commented:

I noticed the same as scharada. I can pretty reliably reproduce this with opening multiple pages of the same site after a change to the source (something not static or Razor template, that means the instance gets recompiled)

orchardbot commented 12 years ago

@Piedone commented:

Now I've accidentally found a reliable way to reproduce the error. Steps (may not all be necessary, but I write all of them just in case):

1) Edit some enabled module's .cs file to force a recompile. 2) Place a breakpoint in the same and start debugging (worth noting: I've tried this with Onestop.Tenants, so that means attaching a debugger to an already open IIS process, unlike hitting F5 that recompiles immediately). 3) Open a page that invokes the code with the breakpoint. 4) The breakpoint is hit. Let the execution continue, but after resuming immediately edit the same code and save. 5) Ideally the page you've opened is still loading. Hit refresh. 6) Before the breakpoint is hit the second time, the below exception comes up in Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.ShapeAttributeBindingStrategy ln. 52.

I guess with sites on the server we can reproduce this occasionally when after a recompile somebody is fetching a page, but meanwhile somebody else enables/disables a module or the instance is updated from the repo.

System.ObjectDisposedException was unhandled by user code Message=Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed. Source=Autofac ObjectName="" StackTrace: at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed() at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters) at Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy.ShapeAttributeBindingStrategy.<>c__DisplayClass4.<CreateDelegate>b__3(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAttributeStrategy\ShapeAttributeBindingStrategy.cs:line 52 at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>c__DisplayClass3.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:line 55 at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 179 at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 88 at Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 71 at Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable1 parameters) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 38 at Orchard.DisplayManagement.Implementation.DisplayHelperFactory.DisplayHelperBehavior.InvokeMember(Func1 proceed, Object target, String name, INamedEnumerable1 args) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelperFactory.cs:line 27 at ClaySharp.ClayBehaviorCollection.<>cDisplayClass14.<>cDisplayClass16.b13() in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29 at ClaySharp.ClayBehaviorCollection.Execute(Func1 proceed, Func3 linker) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 13 at ClaySharp.ClayBehaviorCollection.InvokeMember(Func1 proceed, Object self, String name, INamedEnumerable1 args) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at ASP._Page_Themes_Onestop_CustomAdmin_Views_Layout_cshtml.b__42(Object x) in d:\Orchard\src\Orchard.Web\Themes\Onestop.CustomAdmin\Views\Layout.cshtml:line 21 at CallSite.Target(Closure , CallSite , Func`2 , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at ASP._Page_Themes_Onestop_CustomAdmin_Views_Layout_cshtml.Execute() in d:\Orchard\src\Orchard.Web\Themes\Onestop.CustomAdmin\Views\Layout.cshtml:line 42 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 134 at Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.<>cDisplayClass26.<>cDisplayClass28.b15(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:line 118 at Orchard.DisplayManagement.Descriptors.ShapeAlterationBuilder.<>cDisplayClass3.<>cDisplayClass5.b2(DisplayContext displayContext) in D:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:line 55 at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 179 at Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:line 88 at Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 71 at Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable1 parameters) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:line 38 at Orchard.DisplayManagement.Implementation.DisplayHelperFactory.DisplayHelperBehavior.InvokeMember(Func1 proceed, Object target, String name, INamedEnumerable`1 args) in D:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelperFactory.cs:line 27 at ClaySharp.ClayBehaviorCollection.<>cDisplayClass14.<>cDisplayClass16.b13() in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29 at ClaySharp.ClayBehaviorCollection.Execute(Func1 proceed, Func3 linker) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 13 at ClaySharp.ClayBehaviorCollection.InvokeMember(Func1 proceed, Object self, String name, INamedEnumerable1 args) in C:\Users\sebros\My Projects\Clay\src\ClaySharp\ClayBehaviorCollection.cs:line 29 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.<>cDisplayClass7.b5(ViewContext viewContext, TextWriter writer, IViewDataContainer viewDataContainer) in D:\Orchard\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:line 63 at Orchard.Mvc.ViewEngines.ThemeAwareness.LayoutAwareViewEngine.LayoutView.Render(ViewContext viewContext, TextWriter writer) in D:\Orchard\src\Orchard\Mvc\ViewEngines\ThemeAwareness\LayoutAwareViewEngine.cs:line 90 at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.<>cDisplayClass1c.b19() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) InnerException:

orchardbot commented 12 years ago

@Piedone commented:

OK, I can make the same repro steps with a vanilla instance. Actually at point 4 if you edit the file while the code execution is on hold at the breakpoint it has the same effect then editing it after execution continues (not much of a surprise :-)).

orchardbot commented 12 years ago

@sebastienros commented:

@Piedone, the repro steps you are describing are nothing to do with this bug which is a bout enabling two tenants at the same time. The one you describe had a similar one fixed for 1.4. I'll try to find how I had fixed it to see if a recent change broke it again. You might want to create another bug for this, so we know which ones we want to fix the sooner.

orchardbot commented 12 years ago

@Piedone commented:

Fine, I've opened one here: http://orchard.codeplex.com/workitem/18857

orchardbot commented 11 years ago

@pszmyd commented:

@sebastienroe @Piedone: The underlying problem might be the same for all those "lifetime scope" errors, as they all happen when there is an ongoing shell termination/reloading. For some reason either the lifetime scope gets prematurely disposed, or there are some tasks running that should not be ran at that moment.

orchardbot commented 11 years ago

@pszmyd commented:

Should be @sebastienros - sorry for the typo;)

orchardbot commented 11 years ago

LordSaul commented:

We get this same error when creating a new tenant within our deployed environment (Azure web role). Recycling the application pool seemed to make that error go away

orchardbot commented 10 years ago

@pszmyd commented:

Reopening. This issue still stands. The cause is the work context accessor trying to create new context based on an already disposed shell.

orchardbot commented 10 years ago

@sebastienros commented:

1.x ?