今天发布一个了站点,增加了一些异步调用的代码,发布后出现了一次应用程序池崩溃的问题。崩溃后访问站点出现503错误,应用程序池处于停止状态。
Windows事件日志中对应如下:
日志1:
发生了未经处理的异常,已终止进程。 Application ID: /LM/W3SVC/15/ROOT Process ID: 23808 Exception: System.NullReferenceException Message: 未将对象引用设置到对象的实例。 StackTrace: 在 System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext) 在 System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) 在 System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) 在 System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) 在 System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask) --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(Object s) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch()
日志2:
应用程序: w3wp.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止。 异常信息: System.NullReferenceException 堆栈: 在 System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(System.Object) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch()
日志3:
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2 Faulting module name: KERNELBASE.dll, version: 6.1.7601.18798, time stamp: 0x5507b87a Exception code: 0xe0434352 Fault offset: 0x000000000001aaad Faulting process id: 0x5d00 Faulting application start time: 0x01d0b86f3af9058e Faulting application path: c:\windows\system32\inetsrv\w3wp.exe Faulting module path: C:\Windows\system32\KERNELBASE.dll Report Id: 7bec0e6c-2462-11e5-b24e-c43d8baaa802
Message: 未将对象引用设置到对象的实例。
在你的异步方法里找找哪个参数可能为null,作判断
异步方法会生成单独的线程
internal void AssociateWithCurrentThread(bool setImpersonationContext)
{
this._originalHttpContext = DisposableHttpContextWrapper.SwitchContext(this.HttpContext);
if (setImpersonationContext)
{
this.SetImpersonationContext();
}
this._originalSynchronizationContext = AsyncOperationManager.SynchronizationContext;
AspNetSynchronizationContextBase syncContext = this.HttpContext.SyncContext;
AsyncOperationManager.SynchronizationContext = syncContext;
Guid requestTraceIdentifier = this.HttpContext.WorkerRequest.RequestTraceIdentifier;
if (requestTraceIdentifier != Guid.Empty)
{
CallContext.LogicalSetData("E2ETrace.ActivityID", requestTraceIdentifier);
}
this.HttpContext.ResetSqlDependencyCookie();
this._originalThreadPrincipal = Thread.CurrentPrincipal;
HttpApplication.SetCurrentPrincipalWithAssert(this.HttpContext.User);
this.SetRequestLevelCulture();
if (this.HttpContext.CurrentThread == null)
{
this._setCurrentThreadOnHttpContext = true;
this.HttpContext.CurrentThread = Thread.CurrentThread;
}
this._originalThreadContextCurrent = ThreadContext.Current;
ThreadContext.Current = this;
}
这个方法中某个变量为 null ?能知道第几行代码就好了。
http://ing.cnblogs.com/u/dudu/status/678472/