我正尝试在单个核心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" />
我如何进一步调试这个问题?