31

我花了很多时间(谷歌搜索、反映 .net 二进制文件等)试图解决以下问题:

我在我们的应用程序(ASP.NET MVC + EF4)中看到了死锁。我们有几个 EF 的上下文,它们在请求开始时创建并在最后被处理掉。有时我们会遇到以下情况:ASP.NET 为每个请求创建一个线程,然后线程在访问 EF 上下文时进入“in join or sleep”状态。

大多数死锁线程都有如下堆栈跟踪:

    System.dll!System.ComponentModel.TypeDescriptor.Refresh(object component, bool refreshReflectionProvider) + 0x97 bytes    
    System.Data.dll!System.Data.SqlClient.SqlCommand.DesignTimeVisible.set(bool value) + 0x22 bytes    
    System.Data.dll!System.Data.SqlClient.SqlCommand.SqlCommand(System.Data.SqlClient.SqlCommand from) + 0xc9 bytes    
    System.Data.dll!System.Data.SqlClient.SqlCommand.Clone() + 0x27 bytes    
    System.Data.dll!System.Data.SqlClient.SqlCommand.System.ICloneable.Clone() + 0x9 bytes    
    System.Data.Entity.dll!System.Data.Common.DbCommandDefinition.CreateCommandDefinition(System.Data.Common.DbCommand prototype) + 0x47 bytes    
    System.Data.Entity.dll!System.Data.SqlClient.SqlProviderServices.CreateDbCommandDefinition(System.Data.Common.DbProviderManifest providerManifest, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x21 bytes    
    System.Data.Entity.dll!System.Data.EntityClient.EntityCommandDefinition.EntityCommandDefinition(System.Data.Common.DbProviderFactory storeProviderFactory, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x2a1 bytes    
    System.Data.Entity.dll!System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(System.Data.Common.DbProviderManifest providerManifest, System.Data.Common.CommandTrees.DbCommandTree commandTree) + 0x8e bytes    
    System.Data.Entity.dll!System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(System.Data.Objects.ObjectContext context, System.Data.Common.CommandTrees.DbQueryCommandTree tree, System.Type elementType, System.Data.Objects.MergeOption mergeOption, System.Data.Objects.Span span, System.Collections.ObjectModel.ReadOnlyCollection<System.Collections.Generic.KeyValuePair<System.Data.Objects.ObjectParameter,System.Data.Objects.ELinq.QueryParameterExpression>> compiledQueryParameters) + 0x113 bytes    
    System.Data.Entity.dll!System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(System.Data.Objects.MergeOption? forMergeOption) + 0x310 bytes    
    System.Data.Entity.dll!System.Data.Objects.ObjectQuery<CompuTool.Business.Portal.Desktop>.GetResults(System.Data.Objects.MergeOption? forMergeOption) + 0x55 bytes    
    System.Data.Entity.dll!System.Data.Objects.ObjectQuery<System.__Canon>.System.Collections.Generic.IEnumerable<T>.GetEnumerator() + 0x2f bytes    
    System.Core.dll!System.Linq.Enumerable.SingleOrDefault<CompuTool.Business.Portal.Desktop>(System.Collections.Generic.IEnumerable<CompuTool.Business.Portal.Desktop> source) + 0x10f bytes    
    System.Core.dll!System.Linq.Queryable.SingleOrDefault<CompuTool.Business.Portal.Desktop>(System.Linq.IQueryable<CompuTool.Business.Portal.Desktop> source, System.Linq.Expressions.Expression<System.Func<CompuTool.Business.Portal.Desktop,bool>> predicate) + 0x24e bytes    
>    CompuTool.Presentation.Web.dll!CompuTool.Presentation.Web.Controllers.DesktopStateController.ValidateRequest(CompuTool.Business.Portal.DesktopManagerContext dataContext, CompuTool.Business.Portal.User user, int desktopId) Line 30 + 0x19e bytes    C#
    CompuTool.Presentation.Web.dll!CompuTool.Presentation.Web.Controllers.DesktopStateController.SetDesktopState(CompuTool.Business.Portal.User user, int desktopId, string value) Line 65 + 0x17 bytes    C#
    CompuTool.Presentation.Web.dll!CompuTool.Presentation.Web.Controllers.DesktopStateController.Set(int desktopId, string value) Line 111 + 0x13 bytes    C#
    [Lightweight Function]    
    System.Web.Mvc.dll!System.Web.Mvc.ReflectedActionDescriptor.Execute(System.Web.Mvc.ControllerContext controllerContext, System.Collections.Generic.IDictionary<string,object> parameters) + 0x108 bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionDescriptor actionDescriptor, System.Collections.Generic.IDictionary<string,object> parameters) + 0x27 bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters.AnonymousMethod__12() + 0x81 bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(System.Web.Mvc.IActionFilter filter, System.Web.Mvc.ActionExecutingContext preContext, System.Func<System.Web.Mvc.ActionExecutedContext> continuation) + 0xe6 bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(System.Web.Mvc.ControllerContext controllerContext, System.Collections.Generic.IList<System.Web.Mvc.IActionFilter> filters, System.Web.Mvc.ActionDescriptor actionDescriptor, System.Collections.Generic.IDictionary<string,object> parameters) + 0x13a bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerActionInvoker.InvokeAction(System.Web.Mvc.ControllerContext controllerContext, string actionName) + 0x15f bytes    
    System.Web.Mvc.dll!System.Web.Mvc.Controller.ExecuteCore() + 0x9f bytes    
    System.Web.Mvc.dll!System.Web.Mvc.ControllerBase.Execute(System.Web.Routing.RequestContext requestContext) + 0x14f bytes    
    System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest.AnonymousMethod__5() + 0x3e bytes    
    System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.MakeVoidDelegate.AnonymousMethod__0() + 0x14 bytes    
    System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.EndProcessRequest.AnonymousMethod__d() + 0x36 bytes    
    System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x1d5 bytes    
    System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) + 0x177 bytes    
    System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) + 0x6f5 bytes    
    System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb) + 0x85 bytes    
    System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr, System.Web.HttpContext context) + 0x2b6 bytes    
    System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x3bf bytes    
    System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x22 bytes    
    [Native to Managed Transition]    
    [Managed to Native Transition]    
    System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x4f4 bytes    
    System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x22 bytes 

这个问题是否与不正确的实体框架上下文使用有关?感谢帮助。

4

0 回答 0