我正嘗試在單個核心Windows Server 2012主機上承載ASP.NET Core MVC項目。我正在使用ASP.NET Core MVC 1.0.0並且在.NET Framework 4.6.1的IIS 8上運行該應用程序在第一〜10分鐘內工作正常,然後服務器突然停止響應。ASP.NET Core MVC應用程序請求永遠不會完成
起初我還以爲是在數據庫方面的僵局,所以我說記錄在的DbContext類:
private static long ActiveContextCount = 0;
private ILogger _log;
private Stopwatch _timer = new Stopwatch();
private Guid _contextId = Guid.NewGuid();
public BlogContext(string nameOrConnectionString, ILoggerFactory logger)
:base(nameOrConnectionString)
{
_log = logger.CreateLogger<BlogContext>();
Database.Log = l =>
{
_log.LogInformation(l);
};
ActiveContextCount++;
_timer.Start();
_log.LogInformation("BlogContext created. GUID:{0}, Active count {1}", _contextId, ActiveContextCount);
}
protected override void Dispose(bool disposing)
{
ActiveContextCount--;
_timer.Stop();
_log?.LogInformation("BlogContext Disposed. GUID:{0}, Live time: {1}ms, Active count {2}", _contextId, _timer.ElapsedMilliseconds, ActiveContextCount);
base.Dispose(disposing);
}
我使用實體框架6,我已經設置了的DbContext先限定:
services.AddScoped(p => new BlogContext(_dataDbConnectionString, p.GetRequiredService<ILoggerFactory>()));
原來,數據庫操作一切正常。我跟蹤日誌中的請求,並注意到一些要求有最後一個日誌爲:
[Information] Executing ViewResult, running view at path "/Views/Blog/Details.cshtml".
而且從來沒有完成(即找不到配置在日誌中)。從這一點開始,ActiveContextCount
只是堆成幾百個,整個應用程序掛起並停止響應。
(EDIT 8月29日)又如,沒有查詢被執行,甚至:
[Information] Request starting HTTP/1.1 GET http://myapp/
[Information] UsersContext created. GUID:bb7743b9-7999-4a01-819f-3d239d34d4d9, Active count 7
[Information] HttpContext.User merged via AutomaticAuthentication from authenticationScheme: "Identity.Application".
[Information] BlogContext created. GUID:8c7505d4-5c87-428e-ad56-12f35f54aadc, Active count 6
[Information] Executing action method "MyApp.Controllers.HomeController.Index (MyApp)" with arguments (["1"]) - ModelState is Valid
[Information] Executing ViewResult, running view at path "/Views/Home/Index.cshtml".
我停留在這一點上。爲什麼視圖結果永遠不會結束?這是一個框架或我的應用程序中的錯誤?即使存在錯誤,爲什麼請求只是在某些超時後被中止和放棄?我試着在web.config中指定超時,但沒有幫助:
<aspNetCore processPath=".\MyApp.exe" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" requestTimeout="00:00:40" />
我如何進一步調試這個問題?