2013-03-22 50 views
1

前幾天,我們開始收到以下錯誤在我們的ASP.NET MVC應用程序ELMAH錯誤日誌:ASP.NET MVC兒童行動 - 堆不足,無法繼續執行程序安全

不足棧繼續安全地執行程序。這可能是 發生在調用堆棧上的功能太多或者功能太多,堆棧空間太多。

有問題的應用程序是在Web場中的2個Windows Server 2012服務器上運行的多租戶Web應用程序。在任一服務器上定期發生錯誤(每小時1或2次),但始終在同一租戶URL上。我們已經建立了另一個擁有相同設置(主題等)的租戶,但無法複製該錯誤。它從未發生過發展。

異常和堆棧跟蹤指示某種正在執行的遞歸函數。在堆棧跟蹤的開頭:

System.Web.HttpException(0X80004005):錯誤執行的處理程序 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper' 子請求。 ---> System.Web.HttpException(0x80004005):爲處理程序 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'執行子請求時出錯。 --->

這樣重複85次,纔得到調用堆棧中的下一項。

然後我們有以下幾點:

at System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack() 
    at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) 
    at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) 
    at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag) 
    at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) 
    at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) 
    at System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) 
    at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) 
    at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func) 
    at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) 
    at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) 
    at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) 
    at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) 
    at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) 
    at ASP._Page_Themes_Clik_Views_Shared__Layout_cshtml.Execute() in c:\MySite\wwwroot\Themes\Clik\Views\Shared\_Layout.cshtml:line 15 
    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.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) 
    at System.Web.WebPages.WebPageBase.PopContext() 
    at StackExchange.Profiling.MVCHelpers.ProfilingViewEngine.WrappedView.Render(ViewContext viewContext, TextWriter writer) 
    at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) 
    at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) 
    at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) 
    at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) 
    at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) 
    at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3() 
    at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func) 
    at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) 
    at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) 
    at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) 
    at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) 
    at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) 
    at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) 
    at ASP._Page_Themes_Clik_Views_Shared__Layout_cshtml.Execute() in c:\MySite\wwwroot\Themes\Clik\Views\Shared\_Layout.cshtml:line 15 

從堆棧跟蹤:

在 c。在ASP._Page_Themes_Clik_Views_Shared__Layout_cshtml.Execute():\ mysite的\ wwwroot的\ \主題的Clik \ Views \ Shared_Layout.cshtml:line 15
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()

類似地重複85次,就好像視圖是遞歸執行自己一樣。

的代碼行它指向的是Html.Action呼叫:

public MvcHtmlString Menu(string name, string overrideView = null) 
{ 
    Ensure.Argument.NotNullOrEmpty(name, "name"); 
    return html.Action("_details", "menus", new { name = name, viewName = overrideView }); 
} 

這是由所有的其他住戶和主題顯示的網站導航菜單相同的代碼。 MenusController

[HttpGet] 
public async Task<ActionResult> Details(string name) 
{ 
    var menu = await menusClient.GetMenuByName(
     siteId: siteContext.SiteId, 
     name: name 
    ) 
    .ConfigureAwait(false); 

    if (menu == null) 
    { 
     return HttpNotFound(); 
    } 

    var model = Mapper.Map<MenuDetailsModel>(menu); 
    model.SetCurrentMenuItem(Request.Url);   
    return View("Details", model); 
} 

#region Widget 

[HttpGet, ChildActionOnly] 
public ActionResult _Details(string name) 
{ 
    return Details(name).Result; // this is converted to a partial view result by an action filter 
} 

因爲ASP.NET MVC不支持我們不得不作出一個阻塞調用我們的異步操作中_Details異步孩子的行爲。請注意,我們有一個操作過濾器,負責將ViewResult從Details轉換爲PartialViewResult

正如我所說的,這段代碼在開發和生產(幾乎所有時間)都能正常工作。我試過在MenusController內拋出異常,但我仍然無法複製異常。

+0

這是因爲MvcHtmlString返回html.Action的。我有同樣的問題。 – 2013-10-04 05:01:31

回答

0

試試這個:

public static MvcHtmlString Menu(this HtmlHelper helper, string name, string overrideView = null) 
{ 
    var url = new UrlHelper(htmlHelper.ViewContext.RequestContext); 
    Ensure.Argument.NotNullOrEmpty(name, "name"); 
    return url.Action("_details", "menus", new { name = name, viewName = overrideView }); 
}