4

私は Autofac ユーザーですが、現在非常に頭の痛い問題に直面しています。私はこの質問を Alex と Travis からメールで受けました。彼らから返事がありました。彼らの助けに感謝します。この問題を徹底的にチェックするために、Travis の推奨事項を受け入れ、詳細をここに公開しました。

私のメール:

mvc3 プロジェクトでは Autofac 2.6.3.862 を使用しています。

IIS のデッドロックの問題は深刻です。サーバーが頻繁にハングします。Microsoft Debug Diagnostics Tool を使用して分析を行いました (分析レポートを同封します)。最初は LifetimeScope のロックであると疑われました。

私はあなたの記事を読みましたが、いくつかの技術的な詳細については私にはあいまいです. Register() コンポーネントのほとんどは SingleInstance であるため、Resolve() の場合、 (var scope = Container.BeginLifetimeScope()) を使用するような子のライフタイム スコープは使用しません。

、これがデッドロックの原因かどうかはわかりません。

デバッグ診断分析レポート

The following threads in 
w3wp.exe__hg__PID__3904__Date__03_07_2013__Time_11_01_07AM__974__Manual Dump.dmp are waiting to enter a .NET Lock which thread 39 is currently holding    
( 26 34 42 43 44 45 46 47 48 )    
16.67% of threads blocked    

======================================================================================

Detected possible blocking or leaked critical section at 0x0e758a00 owned by thread 26 in w3wp.exe__hg__PID__3904__Date__03_07_2013__Time_11_01_07AM__974__Manual Dump.dmp 

Impact of this lock    
1.85% of threads blocked

(Threads 39)

The following functions are trying to enter this critical section

clr!UnsafeEEEnterCriticalSection+1c    

The following module(s) are involved with this critical section

C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll

======================================================================================

Thread 26 - System ID 7628
Entry point   0x00000000 
Create time   2013/3/7 10:44:15 
Time spent in user mode   0 Days 00:00:00.218 
Time spent in kernel mode   0 Days 00:00:00.343 




This thread is waiting to enter a .NET Lock which thread 39 is currently holding



.NET Call Stack



Function 
System.Threading.Monitor.ReliableEnter(System.Object, Boolean ByRef) 
System.Threading.Monitor.Enter(System.Object, Boolean ByRef) 
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Container.ResolveComponent(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.TryResolveService(Autofac.IComponentContext, Autofac.Core.Service, System.Collections.Generic.IEnumerable`1, System.Object ByRef) 
Autofac.ResolutionExtensions.ResolveService(Autofac.IComponentContext, Autofac.Core.Service, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.Resolve[[System.__Canon, mscorlib]](Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.Resolve[[System.__Canon, mscorlib]](Autofac.IComponentContext) 
Tunynet.DIContainer.Resolve[[System.__Canon, mscorlib]]() 
Spacebuilder.Common.ProfileRepository..cctor() 
Spacebuilder.Common.ProfileRepository..ctor() 
Spacebuilder.Common.UserProfileService..ctor() 
Spacebuilder.Common.User.get_Profile() 
ASP._Page_Themes_Channel_Default_Views_FindUser__QuickSearch_cshtml.Execute() 
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() 
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() 
Tunynet.UI.ThemedWebViewPage.ExecutePageHierarchy() 
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(System.Web.WebPages.WebPageContext, System.IO.TextWriter, System.Web.WebPages.WebPageRenderingBase) 
Tunynet.UI.ThemedRazorView.RenderView(System.Web.Mvc.ViewContext, System.IO.TextWriter, System.Object) 
System.Web.Mvc.BuildManagerCompiledView.Render(System.Web.Mvc.ViewContext, System.IO.TextWriter) 
System.Web.Mvc.ViewResultBase.ExecuteResult(System.Web.Mvc.ControllerContext) 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(System.Web.Mvc.ControllerContext, System.Web.Mvc.ActionResult) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.b__19() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.b__1b() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.b__1b() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.b__1b() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.b__1b() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(System.Web.Mvc.ControllerContext, System.Collections.Generic.IList`1, System.Web.Mvc.ActionResult) 
System.Web.Mvc.ControllerActionInvoker.InvokeAction(System.Web.Mvc.ControllerContext, System.String) 
System.Web.Mvc.Controller.ExecuteCore() 
System.Web.Mvc.ControllerBase.Execute(System.Web.Routing.RequestContext) 
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(System.Web.Routing.RequestContext) 
System.Web.Mvc.MvcHandler+<>c__DisplayClass6+<>c__DisplayClassb.b__5() 
System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass1.b__0() 
System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass8`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].b__7(System.IAsyncResult) 
System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].End() 
System.Web.Mvc.MvcHandler+<>c__DisplayClasse.b__d() 
System.Web.Mvc.SecurityUtil.b__0(System.Action) 
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(System.Action) 
System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult) 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(System.IAsyncResult) 
System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) 
System.Web.HttpApplication+PipelineStepManager.ResumeSteps(System.Exception) 
System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback) 
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef) 
System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 


Full Call Stack



Function   Source 
ntdll!KiFastSystemCallRet    
ntdll!NtWaitForMultipleObjects+c    
KERNELBASE!WaitForMultipleObjectsEx+100    
kernel32!WaitForMultipleObjectsExImplementation+e0    
clr!WaitForMultipleObjectsEx_SO_TOLERANT+56    
clr!Thread::DoAppropriateAptStateWait+4d    
clr!Thread::DoAppropriateWaitWorker+17d    
clr!Thread::DoAppropriateWait+60    
clr!CLREvent::WaitEx+106    
clr!CLREvent::Wait+19    
clr!AwareLock::EnterEpilogHelper+a8    
clr!AwareLock::EnterEpilog+42    
clr!AwareLock::Enter+5f    
clr!AwareLock::Contention+228    
clr!JITutil_MonReliableContention+e8    
System.Threading.Monitor.Enter(System.Object, Boolean ByRef)    
clr!CallDescrWorker+33    
clr!CallDescrWorkerWithHandler+8e    
clr!DispatchCallBody+20    
clr!DispatchCallDebuggerWrapper+75    
clr!DispatchCallNoEH+53    
clr!MethodTable::RunClassInitEx+f1    
clr!MethodTable::DoRunClassInitThrowing+53e    
clr!MethodDesc::DoPrestub+f1    
clr!PreStubWorker+12c    
0x00f80842    
clr!MethodTable::GetRestoredSlot+2a    
clr!MethodDesc::GetMethodEntryPoint+4e    
clr!MethodDesc::DoPrestub+51d    
clr!PreStubWorker+15d    
0x00f80842    
System.Web.WebPages.WebPageBase.ExecutePageHierarchy()    
System.Web.Mvc.WebViewPage.ExecutePageHierarchy()    
System.Collections.Generic.Stack`1[[System.__Canon, mscorlib]].Push(System.__Canon)    
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(System.Web.WebPages.WebPageContext, System.IO.TextWriter, System.Web.WebPages.WebPageRenderingBase)    
System.RuntimeType+ActivatorCacheEntry..ctor(System.Type, System.RuntimeMethodHandleInternal, Boolean)    
System.Web.Mvc.BuildManagerCompiledView.Render(System.Web.Mvc.ViewContext, System.IO.TextWriter)    
System.Web.Mvc.ViewResultBase.ExecuteResult(System.Web.Mvc.ControllerContext)    
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(System.Web.Mvc.ControllerContext, System.Web.Mvc.ActionResult)    
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()    
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(System.Web.Mvc.IResultFilter, System.Web.Mvc.ResultExecutingContext, System.Func`1<System.Web.Mvc.ResultExecutedContext>)    
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()    
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()    
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()    
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c+<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()    
System.Web.Mvc.ControllerActionInvoker.InvokeAction(System.Web.Mvc.ControllerContext, System.String)    
System.Web.Mvc.Controller.ExecuteCore()    
System.Web.Mvc.ControllerBase.Execute(System.Web.Routing.RequestContext)    
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(System.Web.Routing.RequestContext)    
System.Web.Mvc.MvcHandler+<>c__DisplayClass6+<>c__DisplayClassb.<BeginProcessRequest>b__5()    
System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass1.<MakeVoidDelegate>b__0()    
System.Web.Mvc.MvcHandler+<>c__DisplayClasse.<EndProcessRequest>b__d()    
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(System.Action)    
System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult)    
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(System.IAsyncResult)    
System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    
System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef)    
System.Web.HttpApplication+PipelineStepManager.ResumeSteps(System.Exception)    
System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback)    
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext)    
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)    
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)    
webengine4!W3_MGD_HANDLER::ProcessNotification+5b    
webengine4!W3_MGD_HANDLER::DoWork+250    
webengine4!RequestDoWork+2da    
webengine4!CMgdEngHttpModule::OnExecuteRequestHandler+1a    
iiscore!NOTIFICATION_CONTEXT::RequestDoWork+128    
iiscore!NOTIFICATION_CONTEXT::CallModulesInternal+305    
iiscore!NOTIFICATION_CONTEXT::CallModules+28    
iiscore!W3_CONTEXT::DoStateRequestExecuteHandler+36    
iiscore!W3_CONTEXT::DoWork+d7    
iiscore!W3_MAIN_CONTEXT::ContinueNotificationLoop+1f    
iiscore!W3_MAIN_CONTEXT::ProcessIndicateCompletion+1f    
iiscore!W3_CONTEXT::IndicateCompletion+75    
webengine4!W3_MGD_HANDLER::IndicateCompletion+3d    
webengine4!MgdIndicateCompletion+24    
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef)    
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)    
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)    
clr!UM2MThunk_WrapperHelper+10    
clr!UM2MThunk_Wrapper+8c    
clr!Thread::DoADCallBack+f0    
clr!UM2MDoADCallBack+c0    
0x00f98c20    
webengine4!W3_MGD_HANDLER::ProcessNotification+5b    
webengine4!ProcessNotificationCallback+36    
clr!UnManagedPerAppDomainTPCount::DispatchWorkItem+195    
clr!ThreadpoolMgr::NewWorkerThreadStart+20b    
clr!ThreadpoolMgr::WorkerThreadStart+3d1    
clr!Thread::intermediateThreadProc+4b    
kernel32!BaseThreadInitThunk+e    
ntdll!__RtlUserThreadStart+70    
ntdll!_RtlUserThreadStart+1b 


=========================================================================

Thread 39 - System ID 4176
Entry point   0x00000000 
Create time   2013/3/7 10:44:21 
Time spent in user mode   0 Days 00:00:00.140 
Time spent in kernel mode   0 Days 00:00:00.109 




This thread is not fully resolved and may or may not be a problem. Further analysis of these threads may be required.



.NET Call Stack



Function 
Spacebuilder.Common.ProfileRepository..ctor() 
Spacebuilder.Common.UserProfileService..ctor() 
Spacebuilder.Common.UserSearcher..ctor(System.String, System.String, Boolean, Int32) 
Spacebuilder.Environments.Starter.b__54(Autofac.IComponentContext) 
Autofac.RegistrationExtensions+<>c__DisplayClass10`1[[System.__Canon, mscorlib]].b__f(Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.Builder.RegistrationBuilder+<>c__DisplayClass1`1[[System.__Canon, mscorlib]].b__0(Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.InstanceLookup.Activate(System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.InstanceLookup.b__0() 
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(System.Guid, System.Func`1) 
Autofac.Core.Resolving.InstanceLookup.Execute() 
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(Autofac.Core.ISharingLifetimeScope, Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.InstanceLookup.ResolveComponent(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Features.Collections.CollectionRegistrationSource+<>c__DisplayClass4+<>c__DisplayClass6.b__1(Autofac.Core.IComponentRegistration) 
System.Linq.Enumerable+WhereSelectArrayIterator`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].MoveNext() 
System.Linq.Buffer`1[[System.__Canon, mscorlib]]..ctor(System.Collections.Generic.IEnumerable`1) 
System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1) 
Autofac.Features.Collections.CollectionRegistrationSource+<>c__DisplayClass4.b__0(Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.InstanceLookup.Activate(System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.InstanceLookup.Execute() 
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(Autofac.Core.ISharingLifetimeScope, Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Resolving.ResolveOperation.Execute(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.Core.Container.ResolveComponent(Autofac.Core.IComponentRegistration, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.TryResolveService(Autofac.IComponentContext, Autofac.Core.Service, System.Collections.Generic.IEnumerable`1, System.Object ByRef) 
Autofac.ResolutionExtensions.ResolveService(Autofac.IComponentContext, Autofac.Core.Service, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.Resolve[[System.__Canon, mscorlib]](Autofac.IComponentContext, System.Collections.Generic.IEnumerable`1) 
Autofac.ResolutionExtensions.Resolve[[System.__Canon, mscorlib]](Autofac.IComponentContext) 
Tunynet.DIContainer.Resolve[[System.__Canon, mscorlib]]() 
Spacebuilder.Search.SearcherFactory.GetSearcher(System.String) 
Spacebuilder.Common.FindUserController._InterestedWithAll(Int32, Int32, System.String) 
DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure, System.Web.Mvc.ControllerBase, System.Object[]) 
System.Web.Mvc.ActionMethodDispatcher.Execute(System.Web.Mvc.ControllerBase, System.Object[]) 
System.Web.Mvc.ReflectedActionDescriptor.Execute(System.Web.Mvc.ControllerContext, System.Collections.Generic.IDictionary`2) 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(System.Web.Mvc.ControllerContext, System.Web.Mvc.ActionDescriptor, System.Collections.Generic.IDictionary`2) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass15.b__12() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(System.Web.Mvc.IActionFilter, System.Web.Mvc.ActionExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass15+<>c__DisplayClass17.b__14() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(System.Web.Mvc.IActionFilter, System.Web.Mvc.ActionExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass15+<>c__DisplayClass17.b__14() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(System.Web.Mvc.IActionFilter, System.Web.Mvc.ActionExecutingContext, System.Func`1) 
System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass15+<>c__DisplayClass17.b__14() 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(System.Web.Mvc.ControllerContext, System.Collections.Generic.IList`1, System.Web.Mvc.ActionDescriptor, System.Collections.Generic.IDictionary`2) 
System.Web.Mvc.ControllerActionInvoker.InvokeAction(System.Web.Mvc.ControllerContext, System.String) 
System.Web.Mvc.Controller.ExecuteCore() 
System.Web.Mvc.ControllerBase.Execute(System.Web.Routing.RequestContext) 
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(System.Web.Routing.RequestContext) 
System.Web.Mvc.MvcHandler+<>c__DisplayClass6+<>c__DisplayClassb.b__5() 
System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass1.b__0() 
System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass8`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].b__7(System.IAsyncResult) 
System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncResult`1[[System.Web.Mvc.Async.AsyncVoid, System.Web.Mvc]].End() 
System.Web.Mvc.MvcHandler+<>c__DisplayClasse.b__d() 
System.Web.Mvc.SecurityUtil.b__0(System.Action) 
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(System.Action) 
System.Web.Mvc.MvcHandler.EndProcessRequest(System.IAsyncResult) 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(System.IAsyncResult) 
System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) 
System.Web.HttpApplication+PipelineStepManager.ResumeSteps(System.Exception) 
System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback) 
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef) 
System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32) 
System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32) 


Full Call Stack



Function   Source 
ntdll!KiFastSystemCallRet    
ntdll!NtWaitForSingleObject+c    
ntdll!RtlpWaitOnCriticalSection+13e    
ntdll!RtlEnterCriticalSection+150    
clr!UnsafeEEEnterCriticalSection+1c    
clr!CrstBase::Enter+1ad    
clr!ListLockEntry::FinishDeadlockAwareEnter+25    
clr!ListLockEntry::LockHolder::DeadlockAwareAcquire+28    
clr!MethodTable::DoRunClassInitThrowing+4c2    
clr!MethodDesc::DoPrestub+f1    
clr!PreStubWorker+12c    
0x00f80842    
clr!PreStubWorker+165    
System.Linq.Enumerable+WhereSelectArrayIterator`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].MoveNext()    
System.Linq.Buffer`1[[System.__Canon, mscorlib]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)    
System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1<System.__Canon>)    
System.Collections.Generic.Stack`1[[System.__Canon, mscorlib]].Push(System.__Canon)    
clr!JIT_Stelem_Ref+25    
System.Collections.Generic.Stack`1[[System.__Canon, mscorlib]].Push(System.__Canon) 

アレックス 返信:

これはトリッキーなもののように聞こえます。DIContainer クラスは何をしていますか? InstancePerHttpRequest または InstancePerLifetimeScope として登録されているコンポーネントはありますか? バックグラウンドにもいくつかの Quartz ジョブがあるようですが、それらはコンテナとどのようにやり取りしていますか?

トラビス 返信:

スタック トレースをざっと見てみると、Spacebuilder.Environments.Starter、Spacebuilder.Common.UserSearcher.ctor、Spacebuilder.UserProfileService.ctor、または Spacebuilder.Common.ProfileRepository で実行時間の長い操作またはロックが発生している可能性があることがわかります。興味深いのは、RESOLVE 操作中にコンポーネントが RESOLVED になると、内部 REGISTER が行われるということです。コードを見ないと何が起こっているのかわかりませんが、そのスレッド - #39 - は私が見たいものです。

次のように見えます... コントローラーアクションが呼び出されています クロージャー (DynamicClass.lambda_method) で実行されているある種のラムダがあります - パイプラインでカスタム化されたものです。SearcherFactory.GetSearcher は手動で平滑化を解決しようとします。GetSearcher での解決中に、サービスの IEnumerable など、何かがコレクションを要求しています。コンストラクターのパラメーター? ここが奇妙になります: その IEnumerable を解決している間、新しい有効期間スコープが作成され、何かが登録されているように見えますか? LifetimeScope.ResolveComponent 呼び出しは、解決がスレッドセーフであることを確認するためにロックを行います。デッドロックが発生しているという事実は、2 つの異なるスレッドが同じ有効期間スコープ (コンテナー?) から同時に解決しようとしていることを意味します。これは、MVC では、は避けるべきものです。たとえば、一度に 1 つのスレッドにしか存在しないため、HttpRequest のライフタイム スコープからのみ解決する場合は、おそらくこれに遭遇することはありません。または、サービスの場所を特定する目的で、アプリ内で有効期間スコープを渡している可能性があり、これも危険信号になる可能性があります。

Concurrency に関する wiki ページもあり、いくつかの指針を示すことができます: https://code.google.com/p/autofac/wiki/Concurrency

必要な方向に進まない場合は、ディスカッション フォーラムに投稿することをお勧めします。これもまた、必ずしもタイムリーに個別のヘルプを提供できるとは限らないためです。そうすることで他の人の目に留まり、より早く助けてもらえるかもしれません。含める必要があるもの: 問題の説明 (このメールにあったようなもの) と、予想されることの詳細 (たとえば、何とか何とかするコントローラー アクションにアクセスしているなど)。ブロッキング スレッドのスタック トレース。物事がブロックされている場所のコード: 物事がどのように登録されているかを示すための最初の ContainerBuilder 登録。それらのコンストラクターとハングアップしているものには何がありますか。その情報は、人々が問題をより迅速に根絶するのに役立ちます. それか'

私の補足質問の詳細:

サーバーは頻繁に不規則にハングします。iisreset コマンドを使用してサーバーを再起動すると、ブラウザが突然応答しなくなります。コントローラーが呼び出されたのか、その時にいくつかの Quartz タスクがトリガーされたのかはわかりません。

Application_Start() では、ContainerBuilder.Register() を使用して、多くのコンポーネントを同じルート ライフタイム スコープに登録します。そして、これらのコンポーネントは相互に呼び出すことができます。

それらのほとんどは、次のように SingleInstance として登録されています。

containerBuilder.Register(c => new DefaultCacheService(new MemcachedCache())).As<ICacheService>().SingleInstance();
containerBuilder.Register(c => new QuartzTaskScheduler()).As<ITaskScheduler>().SingleInstance();
containerBuilder.Register(c => new UserService()).As<IUserService>().SingleInstance();
containerBuilder.Register(c => new UserSearcher("~/App_Data/IndexFiles/User")).As<ISearcher>().SingleInstance();
containerBuilder.Register(c => new TagSearcher("~/App_Data/IndexFiles/Tag")).As<ISearcher>().SingleInstance();

InstancePerHttpRequest として登録されているのはごくわずかで、これらのコンポーネントの初期化は各リクエストに関連しています。そのような:

containerBuilder.Register(c => new FormsAuthenticationService()).As<IAuthenticationService>().InstancePerHttpRequest();

コンポーネントを解決するためのいくつかの単純な静的メソッドを含むクラス (DIContainer) を提供します。静的メソッドは、一部のコントローラー、サービス、リポジトリ (DAO)、または Quartz タスクなどで、コンポーネントを解決するときに呼び出されます。

IContainer container = containerBuilder.Build();
DIContainer.RegisterContainer(container); 
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

public class DIContainer
{
   private static IContainer _container;

   public static void RegisterContainer(IContainer container)
   {
       _container = container;
   }

   public static TService Resolve<TService>()
   {
       return _container.Resolve<TService>();
   }
   ......
}

全文検索サービスには Lucene.Net を使用しており、各 ISearcher は検索の種類とインデックス ディレクトリに対応しています。ISearcher は、必要に応じて SearcherFactory.GetSearcher() で解決されます。

public static ISearcher GetSearcher(string IndexPath)
{
   return DIContainer.Resolve<IEnumerable<ISearcher>>().Where(s => s.IndexPath.Equals(IndexPath, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
}

それはそうですが、根本的な理由はまだわかりません。あなたの助けを願っています。

4

1 に答える 1

1

Resolve メソッドの内部実装は LifetimeScope.GetOrCreateAndShare です。このメソッドはスレッド ロックを使用します。ProfileRepository の静的コンストラクターを確認してください。コンストラクターのスレッド ロックと autofac のスレッド ロックがデッドロックを構成している可能性があります。

于 2013-03-20T04:36:56.803 に答える