ASP.NET站点自动重启问题排查

发表于:2013-1-25 09:47

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:kaosini    来源:51Testing软件测试网采编

  项目中遇到的问题

  排查原因

  最近调试一个东西,写了个监控页面,发现自己Cache的数据在设定的过期时间远远还没有到的时候就过期了,于是我着手排查了下出现问题的原因:

  1、程序会删除缓存 -- 查找了整个项目,发现程序里根本没有删除缓存的操作,所以这个原因可以排除。

  2、写缓存的方法有问题 -- 这个也可以排除,因为很多地方用这个dll,其它项目不存在这个bug,所以这个原因也可以排除。

  3、服务器上有清除所有内存的程序 -- 于是一个个服务终止了下,最后发现终止了一个动转静服务后,程序就没有异常了,所以这个问题是因为动转静服务引起的了。

  解决方案

  反编译了这个动转静服务的源码,发现并没有清理内存的操作,于是想到了是不是因为动转静服务的什么操作,引起了应用程序池Appliacation_End,然后cache都被回收了。于是在Global.asax里面的Application_End方法里写了下面的代码,用于记录是否引起了这个事件,以及引起事件触发的原因。

protected void Application_End(object sender, EventArgs e)
{
    HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime",
        BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField,
        null,
        null,
        null);
 
    if (runtime == null)
        return;
 
    string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage",
        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField,
        null,
        runtime,
        null);
 
    string shutDownStack = (string)runtime.GetType().InvokeMember(
        "_shutDownStack",
        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField,
        null,
        runtime,
        null);
 
    if (!EventLog.SourceExists(".NETRuntime"))
    {
 
        EventLog.CreateEventSource(".NETRuntime", "Application");
 
    }
 
    EventLog log = new EventLog();
 
    log.Source = ".NET Runtime";
 
    log.WriteEntry(String.Format("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}", shutDownMessage, shutDownStack), EventLogEntryType.Error);
}

  结果,日志文件里头果然有记录,记录都为:

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

  The description for Event ID ( 0 ) in Source ( .NET Runtime ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event:

  _shutDownMessage=Recompilation limit of 15 reached
  HostingEnvironment initiated shutdown
  HostingEnvironment caused shutdown

  _shutDownStack=   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
     at System.Environment.get_StackTrace()
     at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
     at System.Web.Hosting.HostingEnvironment.InitiateShutdown()
     at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)
     at System.Web.Compilation.DiskBuildResultCache.ShutdownCallBack(Object state)
     at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state).

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

31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号