接口服务运行一段时间后,IIS应用池就会突然挂掉,事件查看日志,会有事件日志Event ID为5011的错误

为应用程序池“PokeIn”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“”。数据字段包含错误号。

最后直接程序池直接被禁用

应用程序池“PokeIn”将被自动禁用,原因是为此应用程序池提供服务的进程中出现一系列错误。

查看管理事件

Application Error

错误应用程序名称: w3wp.exe,版本: 7.5.7601.17514,时间戳: 0x4ce7a5f8

错误模块名称: KERNELBASE.dll,版本: 

6.1.7601.17514,时间戳: 0x4ce7bafa

异常代码: 0xe0434352
错误偏移量: 0x0000b727
错误进程 ID: 0xc1c
错误应用程序启动时间: 0x01d045ca298f9b3c
错误应用程序路径: C:\Windows\SysWOW64\inetsrv\w3wp.exe
错误模块路径: C:\Windows\syswow64\KERNELBASE.dll
报告 ID: eb60afd0

-b1bd-11e4-9f2d-005056a934bb

.NET Runtime

Application: w3wp.exe Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.
Exception Info: System.AggregateException
Stack:
at System.Threading.Tasks.TaskExceptionHolder.Finalize()

初步排查代码确定有可能的几点

1.项目中使用了dapper ,使用了using,跟踪了源码发现已经有对连接池的处理

int flagNum = new SqlConnection(DBSetting.XXX).Execute("SPS_BookForApp", param, commandType: CommandType.StoredProcedure);

2.由之前的委托异步改为基于任务Task的异步

Func<string, string> func = f =>
{
if (!string.IsNullOrEmpty(orderNo) &&orderNo.IsPositiveInt())
{
//记录订单量
}
else
{
return string.Empty;
}
};
func.BeginInvoke("Logging Order Data", ir =>
{
var ar = (AsyncResult)ir;
var fun = (Func<string, string>)ar.AsyncDelegate;
string returnValue = fun.EndInvoke(ir);
if (!string.IsNullOrEmpty(returnValue))
{
//判断是否记录成功
}
}, null);

改为

Task.Factory.StartNew(() =>
{
//
})

没有去捕获异常,想起之前看过的dudu说过这样的问题 ,于是修改了下

var task = Task.Factory.StartNew(() =>
{
throw new MyCustomException("Task1 faulted.");
})
.ContinueWith((t) =>
{
Console.WriteLine("I have observed a {0}", t.Exception.InnerException.GetType().Name);
}, TaskContinuationOptions.OnlyOnFaulted);

现运行良好。

Refer:
Exception Handling (Task Parallel Library)

https://msdn.microsoft.com/en-us/library/dd997415.aspx

http://www.cnblogs.com/dudu/archive/2012/04/05/task_unhandled_exception_application_crash.html

Exception Handling with the Task Parallel Library

http://www.ademiller.com/blogs/tech/2010/10/exception-handling-with-the-task-parallel-library/

Exception while running system threading tasks task

http://stackoverflow.com/questions/15804059/exception-while-running-system-threading-tasks-task

http://stackoverflow.com/questions/7883052/a-tasks-exceptions-were-not-observed-either-by-waiting-on-the-task-or-accessi/7883083

System.Threading.Tasks.Task 引起的 IIS 应用池崩溃的更多相关文章

  1. System.Threading.Tasks.Task引起的IIS应用程序池崩溃

    问题现象 IIS应用程序池崩溃(Crash)的特征如下: 1. 从客户端看,浏览器一直处于连接状态,Web服务器无响应. 2. 从服务器端看(Windows Server 2008 + IIS 7.0 ...

  2. System.Threading.Tasks.Task 任务引起的IIS应用程序池崩溃

    转载:http://www.cnblogs.com/aaa6818162/p/4421305.html 问题现象 IIS应用程序池崩溃(Crash)的特征如下: 1. 从客户端看,浏览器一直处于连接状 ...

  3. Threading.Tasks.Task多线程 静态全局变量(字典) --只为了记录

    --------------------------------------------------------------后台代码---------------------------------- ...

  4. .Net多线程编程—System.Threading.Tasks.Parallel

    System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...

  5. HttpClient exception:ExceptionType:System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation ca

    error msg: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System. ...

  6. 转载 Net多线程编程—System.Threading.Tasks.Parallel

    .Net多线程编程—System.Threading.Tasks.Parallel   System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Paral ...

  7. 一、并行编程 - 数据并行 System.Threading.Tasks.Parallel 类

    一.并行概念 1.并行编程 在.NET 4中的并行编程是依赖Task Parallel Library(后面简称为TPL) 实现的.在TPL中,最基本的执行单元是task(中文可以理解为"任 ...

  8. System.Threading.Tasks

    前言: 我们之前介绍了两种构建多线程软件的编程技术(使用异步委托或通过System.Threading的成员).这两个可以在任何版本的.NET平台工作. 关于System.Threading 的介绍 ...

  9. .NET 4.0 System.Threading.Tasks学习笔记

    由于工作上的需要,学习使用了System.Threading.Tasks的使用,特此笔记下来. System.Threading.Tasks的作用: Tasks命名空间下的类试图使用任务的概念来解决线 ...

随机推荐

  1. python中的\n、\r与\b

    python中使用print函数,有时候会使用end参数来控制字符输出效果,这时候\n.\r与\b就派上用场了. \n 代表换行,也就是从本行换到下一行 \r 代表回车,也就是回到本行最开始的位置,从 ...

  2. Java利用MethodHandle实现反射时调用super的method

    一:实现 1.Base类的实现 package me.silentdoer.reflecsuper; /** * @author silentdoer * @version 1.0 * @descri ...

  3. php,判断ajax,get,post

    PHP自定义函数判断是否为Get.Post及Ajax提交的方法 /** * 是否是AJAx提交的 * @return bool */ function isAjax(){ if(isset($_SER ...

  4. Windows 下 Quartus 检测不到 USB-Blaster 终极解决办法

    转自https://blog.csdn.net/acang301/article/details/50471067?locationNum=12 一.Windows无法正常驱动USB-Blaster ...

  5. sas和ssd盘写入数据效率对比

    表结构如下: CREATE TABLE `tab_AAA` (  `id` bigint(20) NOT NULL AUTO_INCREMENT ,  `customer_no` varchar(32 ...

  6. web项目文件夹上传

    最近公司做工程项目,实现文件夹上传 网上找了很久,发现网上很多代码大都存在很多问题,不过还是让我找到了一个符合要求的项目. 对项目的文件夹上传功能做出分析,找出文件夹上传的原理,对文件夹的传输模式深入 ...

  7. sea.js教程

    转载自:http://blog.codinglabs.org/articles/modularized-javascript-with-seajs.html 前言 SeaJS是一个遵循CommonJS ...

  8. Mybatis类型转换介绍

    1.1     目录 1.2     建立TypeHandler 1.2.1    TypeHandler接口 1.2.2    BaseTypeHandler抽象类 1.3     注册TypeHa ...

  9. 关于java弱引用

    最近在学java虚拟机相关的东西,看了一篇微信的推送  在此分享https://mp.weixin.qq.com/s/oLhZWWWIVc90cNUBukkqHw 一.强引用 强引用就是我们经常使用的 ...

  10. 新建django需要设置的地方

    urls:urlpatterns = [ path('admin/', admin.site.urls), path('login/', views.Login.as_view())#类方法url对应 ...