ASP.NET Core 5部署IIS应用池随机崩溃排查求助
ASP.NET Core 5.0部署在Windows Server 2008 R2 IIS 7.5的崩溃问题
部署ASP.NET Core 5.0到Windows Server 2008 R2的IIS 7.5环境后,当在线用户数超过20时出现异常,刷新应用会随机崩溃并返回503 Service Unavailable响应。
核心崩溃警告日志
堆栈溢出异常
dumpproc version 1.249.198.20220919-114646, installer version 1.249.198.20220919-114646 time: 2022-10-05 20:32:40 UTC, processId: 69908, path: C:\Program Files\dotnet\dotnet.exe Exception 0xc00000fd: A new guard page for the stack cannot be created.
线程堆栈溢出详情
dumpproc version 1.249.198.20220919-114646, installer version 1.249.198.20220919-114646 time: 2022-10-05 20:32:40 UTC, processId: 69908, path: C:\Program Files\dotnet\dotnet.exe Number of threads: 114 ThreadId 0xE628 - Stack: [0xDB36400000 - 0xDB36580000] Total Size: 1536 kB (committed: 1532kB) +++STACK OVERFLOW+++ [0xDB36400000 - 0xDB36401000] Size: 0x1000 Type: MEM_PRIVATE State: MEM_RESERVE Protect: (0x0) [0xDB36401000 - 0xDB36580000] Size: 0x17F000 Type: MEM_PRIVATE State: MEM_COMMIT Protect: PAGE_READWRITE(0x4)
DebugDiag分析日志
分析摘要
Analysis Summary Warning Description Recommendation 50 client connection(s) in w3wp.exe__mygame.com(domain)(4.0)(pool)__PID__10776__Date__10_06_2022__Time_07_28_18PM__382__Manual Dump.dmp have been executing a request for more than 90 seconds. Please see the Client Connections section of this report for more detailed information about the connection(s). Notification Description Recommendation One or more of the selected rules were not completed. See the Analysis Rule Summary for more information. DebugDiag did not detect LeakTrack.dll loaded in w3wp.exe__mygame.com(domain)(4.0)(pool)__PID__10776__Date__10_06_2022__Time_07_28_18PM__382__Manual Dump.dmp, so no leak analysis was performed on this file. If you are troubleshooting a memory leak, please ensure LeakTrack.dll is injected into the target process using the DebugDiag tool before or generating new dumps. For information regarding installation and usage of the IISDiag tool, please see the included help file. Analysis results may be incomplete because an error occurred while initializing the CLR diagnostic runtime for w3wp.exe__mygame.com(domain)(4.0)(pool)__PID__10776__Date__10_06_2022__Time_07_28_18PM__382__Manual Dump.dmp. Dump File: w3wp.exe__mygame.com(domain)(4.0)(pool)__PID__10776__Date__10_06_2022__Time_07_28_18PM__382__Manual Dump.dmp Type: Microsoft.Diagnostics.Runtime.ClrDiagnosticsException Message: This runtime is not initialized and contains no data. Stack Trace: Microsoft.Diagnostics.Runtime.RuntimeBase..ctor(DataTargetImpl dataTarget, DacLibrary lib) Microsoft.Diagnostics.Runtime.Desktop.V45Runtime..ctor(DataTargetImpl dt, DacLibrary lib) Microsoft.Diagnostics.Runtime.DataTargetImpl.CreateRuntime(String dacFilename) DebugDiag.DotNet.NetDbgObj.CreateRuntime(String symbolPath, DataTarget target, Int32 runtimeIndex, ClrInfo& clrInfo) DebugDiag.DotNet.NetDbgObj.CreateRuntimeAndGetHeap(String dumpPath, IDbgObj4 legacyDebugger, String symbolPath, Boolean throwOnBitnessMismatch, Boolean loadClrHeap) HResult: RuntimeUninitialized This message means that the CLR Runtime is loaded but the ThreadStore or GC Heap information is not initialized. Analysis Details
内存压力分析报告
**MemoryAnalysis** Report for w3wp.exe__teslagame.ir(domain)(4.0)(pool)__PID__10776__Date__10_06_2022__Time_07_28_18PM__382__Manual Dump.dmp Type of Analysis Performed Memory Pressure Analysis Machine Name SERVER Operating System Windows Server - 17763 Number Of Processors 32 Process ID 10776 Process Image c:\Windows\System32\inetsrv\w3wp.exe Command Line c:\windows\system32\inetsrv\w3wp.exe -ap "teslagame.ir(domain)(4.0)(pool)" -v "v4.0" -l "webengine4.dll" -a \\.\pipe\iisipm600e3b22-7687-4999-be3c-7bb5e8a2a29d -h "C:\inetpub\temp\apppools\teslagame.ir(domain)(4.0)(pool)\teslagame.ir(domain)(4.0)(pool).config" -w "" -m 0 -t 5 -ta 1 System Up-Time 17:59:36 Process Up-Time 17:59:17 Processor Type X64 Process Bitness 64-Bit Virtual Memory Analysis Virtual Memory Summary Size of largest free VM block 124.3 TBytes Free memory fragmentation 1.35% Free Memory 126 TBytes (98.43% of Total Memory) Reserved Memory 2 TBytes (1.57% of Total Memory) Committed Memory 238.64 MBytes (0% of Total Memory) Total Memory 128 TBytes Largest free block at 0x000001a8`1a690000
根源定位与解决方案
核心问题判断
从日志可以明确:0xc00000fd堆栈溢出异常是直接崩溃原因——dotnet.exe进程的线程堆栈被耗尽,无法创建新的堆栈保护页,导致进程终止,IIS返回503。同时大量请求超时(超过90秒),说明请求处理链路存在阻塞、死锁或无限递归/循环逻辑。
排查与修复步骤
- 检查代码递归逻辑:搜索项目中未正确终止的递归函数,这类逻辑在并发场景下会快速耗尽线程堆栈。
- 分析长耗时请求:针对超时超过90秒的接口,排查是否存在同步调用外部服务未设超时、数据库慢查询、死锁等阻塞情况。
- 调整线程堆栈大小:64位系统下ASP.NET Core默认线程堆栈为1MB,可通过
runtimeconfig.json增大:{ "runtimeOptions": { "configProperties": { "System.Threading.Thread.MinStackSize": 10485760 // 10MB,按需调整 } } } - 优化IIS应用池配置:
- 设置合理的请求队列长度,避免请求堆积;
- 配置进程回收规则,定时回收进程释放资源;
- 启用快速失败保护并调整阈值,防止崩溃扩散。
- 验证.NET Core兼容性:Windows Server 2008 R2需要.NET Core 5.0的特定补丁支持,确保安装最新的.NET Core 5.0运行时更新,修复已知的线程或内存管理bug。
- 捕获完整.NET堆栈:使用Visual Studio或
dotnet-dump工具捕获崩溃时的完整.NET堆栈,定位到具体出错的代码行。
临时缓解措施
- 增加应用池最大工作进程数,分散并发压力;
- 为长耗时接口添加超时限制,避免线程被长时间占用。
内容的提问来源于stack exchange,提问作者Hossein Azad
相关产品推荐
相关产品推荐

