分析 Asp.net 死锁故障转储

Posted

技术标签:

【中文标题】分析 Asp.net 死锁故障转储【英文标题】:Analyzing Asp.net deadlock crash dump 【发布时间】:2011-07-22 08:10:56 【问题描述】:

我的 asp.net 出现了死锁。我不知道它来自哪里(什么函数),不谈论那个函数在哪里。

我使用 adplus (http://support.microsoft.com/?ID=828222) 生成了转储文件

然后使用Debug Diag & windbg 找到问题。 (还没有成功.. :( )

我的想法没了!请帮帮我...

(Windows 2003,Asp.net 2,32 位)

Windbg 转储:

This dump file has a breakpoint exception stored in it.
The stored exception information can be accessed via .ecxr.
eax=7ffda000 ebx=00000001 ecx=00000002 edx=00000003 esi=00000004 edi=00000005
eip=7c81a251 esp=082affcc ebp=082afff4 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
ntdll!DbgBreakPoint:
7c81a251 cc              int     3
0:032> .loadby sos mscorwks 
Unable to find module 'mscorwks '
0:032> .loadby sos mscorwks
0:032> .load C:\psscor2\x86\psscor2.dll
0:032> .load C:\psscor2\sosex.dll

0:032> kL

ChildEBP RetAddr  
082affc8 7c83fc40 ntdll!DbgBreakPoint
082afff4 00000000 ntdll!DbgUiRemoteBreakin+0x36

0:032> !threads

ThreadCount: 23
UnstartedThread: 0
BackgroundThread: 17
PendingThread: 0
DeadThread: 6
Hosted Runtime: no
                                      PreEmptive   GC Alloc           Lock
       ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception
  12    1  a10 000d3a70   1808220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  14    2  a88 000eccf8      b220 Enabled  00000000:00000000 000e03f8     0 MTA (Finalizer)
  15    3  bec 00105d58    80a220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Completion Port)
  16    4  f04 00108cf0      1220 Enabled  00000000:00000000 000e03f8     0 Ukn
  18    5  dc0 0015c4b0   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  19    6  e24 0013a980   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  20    7  cc8 00178538   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  21    f  db0 0017ed58   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  10   11 1704 05a569a8   880a220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Completion Port)
   6   12 172c 05a5c070       220 Enabled  00000000:00000000 000e03f8     0 Ukn
   4   13   84 05a5af20       220 Enabled  00000000:00000000 000e03f8     0 Ukn
   3   14  910 05a5ab50       220 Enabled  00000000:00000000 000e03f8     0 Ukn
   5   15 1270 05a565d8       220 Enabled  00000000:00000000 000e03f8     0 Ukn
  22    b  8f8 0017be18   200b220 Enabled  00000000:00000000 001093e0     1 MTA
  24   20 11cc 08143240   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  25   1b  ac4 080b3228   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
  26    8 1470 08039b90   180b220 Enabled  00000000:00000000 000e03f8     0 MTA (Threadpool Worker)
XXXX    a    0 0808dc98   1801820 Enabled  00000000:00000000 000e03f8     0 Ukn (Threadpool Worker)
XXXX   1d    0 081cab88   1801820 Enabled  00000000:00000000 000e03f8     0 Ukn (Threadpool Worker)
XXXX   10    0 080686a0   1801820 Enabled  00000000:00000000 000e03f8     0 Ukn (Threadpool Worker)
XXXX   1c    0 08112bf8   1801820 Enabled  00000000:00000000 000e03f8     0 Ukn (Threadpool Worker)
XXXX   19    0 0af46a38   1801820 Enabled  00000000:00000000 000e03f8     0 Ukn (Threadpool Worker)
XXXX   1f    0 0b1fa510      9820 Enabled  00000000:00000000 000e03f8     0 Ukn


0:032> ~22s

eax=02656ae8 ebx=059ee7e8 ecx=00000005 edx=00000538 esi=059ee7ec edi=7ffda000
eip=7c82847c esp=059ee79c ebp=059ee844 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
ntdll!KiFastSystemCallRet:
7c82847c c3              ret

0:022> kL

ChildEBP RetAddr  
059ee798 7c827b89 ntdll!KiFastSystemCallRet
059ee79c 77e6202c ntdll!NtWaitForMultipleObjects+0xc
059ee844 79fccf6a kernel32!WaitForMultipleObjectsEx+0x11a
059ee8ac 79fccb97 mscorwks!WaitForMultipleObjectsEx_SO_TOLERANT+0x6f
059ee8cc 79fccca0 mscorwks!Thread::DoAppropriateAptStateWait+0x3c
059ee950 79fccd35 mscorwks!Thread::DoAppropriateWaitWorker+0x13c
059ee9a0 7a0da8eb mscorwks!Thread::DoAppropriateWait+0x40
*** WARNING: Unable to verify checksum for mscorlib.ni.dll
059eeadc 047cb3ff mscorwks!WaitHandleNative::CorWaitMultipleNative+0x1ec
*** WARNING: Unable to verify checksum for System.ni.dll
059eeb00 7a55fc89 mscorlib_ni+0x1cb3ff
059eeb54 04816e46 System_ni+0x11fc89
059eeb60 04835781 mscorlib_ni+0x216e46
059eeb70 79e71b4c mscorlib_ni+0x235781
059eeb80 79e896ce mscorwks!CallDescrWorker+0x33
059eec00 79e96ea9 mscorwks!CallDescrWorkerWithHandler+0xa3
059eed44 79e96edc mscorwks!MethodDesc::CallDescr+0x19c
059eed60 79e96efa mscorwks!MethodDesc::CallTargetWorker+0x1f
059eed78 79ef2bf9 mscorwks!MethodDescCallSite::CallWithValueTypes+0x1a
059eef44 79ef2d4e mscorwks!ExecuteCodeWithGuaranteedCleanupHelper+0x9f
059eeff4 04835677 mscorwks!ReflectionInvocation::ExecuteCodeWithGuaranteedCleanup+0x10f
059ef010 048202a5 mscorlib_ni+0x235677

0:022> !clrstack

OS Thread Id: 0x8f8 (22)
ESP       EIP     
059eea20 7c82847c [HelperMethodFrame_1OBJ: 059eea20] System.Threading.WaitHandle.WaitMultiple(System.Threading.WaitHandle[], Int32, Boolean, Boolean)
059eeaec 047cb3ff System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[], Int32, Boolean)
059eeb0c 7a55fc89 System.Net.TimerThread.ThreadProc()
059eeb5c 04816e46 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
059eeb68 04835781 System.Threading.ExecutionContext.runTryCode(System.Object)
059eef98 79e71b4c [HelperMethodFrame_PROTECTOBJ: 059eef98] System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
059ef000 04835677 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
059ef01c 048202a5 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
059ef034 04816dc4 System.Threading.ThreadHelper.ThreadStart()
059ef260 79e71b4c [GCFrame: 059ef260] 
059ef550 79e71b4c [ContextTransitionFrame: 059ef550] 

0:022> !mk

Thread 22:
     ESP      EIP
00:U 059ee79c 7c82847c ntdll!KiFastSystemCallRet
01:U 059ee7a0 7c827b89 ntdll!NtWaitForMultipleObjects+0xc
02:U 059ee7a4 77e6202c kernel32!WaitForMultipleObjectsEx+0x11a
03:U 059ee84c 79fccf6a mscorwks!WaitForMultipleObjectsEx_SO_TOLERANT+0x6f
04:U 059ee8b4 79fccb97 mscorwks!Thread::DoAppropriateAptStateWait+0x3c
05:U 059ee8d4 79fccca0 mscorwks!Thread::DoAppropriateWaitWorker+0x13c
06:U 059ee958 79fccd35 mscorwks!Thread::DoAppropriateWait+0x40
07:U 059ee9a8 7a0da8eb mscorwks!WaitHandleNative::CorWaitMultipleNative+0x1ec
08:M 059eeae4 047cb3ff System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[], Int32, Boolean)(+0x88 IL)(+0x8f Native)
09:M 059eeb08 7a55fc89 System.Net.TimerThread.ThreadProc()(+0x14d IL)(+0x2f9 Native)
0a:M 059eeb5c 04816e46 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)(+0xfffffffd IL)(+0x66 Native)
0b:M 059eeb68 04835781 System.Threading.ExecutionContext.runTryCode(System.Object)(+0x0 IL)(+0x51 Native)
0c:U 059eeb78 79e71b4c mscorwks!CallDescrWorker+0x33
0d:U 059eeb88 79e896ce mscorwks!CallDescrWorkerWithHandler+0xa3
0e:U 059eec08 79e96ea9 mscorwks!MethodDesc::CallDescr+0x19c
0f:U 059eed4c 79e96edc mscorwks!MethodDesc::CallTargetWorker+0x1f
10:U 059eed68 79e96efa mscorwks!MethodDescCallSite::CallWithValueTypes+0x1a
11:U 059eed80 79ef2bf9 mscorwks!ExecuteCodeWithGuaranteedCleanupHelper+0x9f
12:U 059eef4c 79ef2d4e mscorwks!ReflectionInvocation::ExecuteCodeWithGuaranteedCleanup+0x10f
13:M 059eeffc 04835677 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)(+0xfffffffd IL)(+0x67 Native)
14:M 059ef018 048202a5 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)(+0xfffffffd IL)(+0x45 Native)
15:M 059ef030 04816dc4 System.Threading.ThreadHelper.ThreadStart()(+0xfffffffd IL)(+0x44 Native)
16:U 059ef048 79e71b4c mscorwks!CallDescrWorker+0x33
17:U 059ef058 79e896ce mscorwks!CallDescrWorkerWithHandler+0xa3
18:U 059ef0d8 79e96ea9 mscorwks!MethodDesc::CallDescr+0x19c
19:U 059ef214 79e96edc mscorwks!MethodDesc::CallTargetWorker+0x1f
1a:U 059ef230 79e96efa mscorwks!MethodDescCallSite::CallWithValueTypes+0x1a
1b:U 059ef248 79f88357 mscorwks!ThreadNative::KickOffThread_Worker+0x192
1c:U 059ef430 79e9cc8f mscorwks!Thread::DoADCallBack+0x32a
1d:U 059ef444 79e9cc2b mscorwks!Thread::ShouldChangeAbortToUnload+0xe3
1e:U 059ef4d8 79e9cb51 mscorwks!Thread::ShouldChangeAbortToUnload+0x30a
1f:U 059ef514 79eb392a mscorwks!Thread::RaiseCrossContextException+0x434
20:U 059ef524 79eb48b9 mscorwks!Thread::DoADCallBack+0xda
21:U 059ef5d4 79eb394b mscorwks!Thread::DoADCallBack+0x310
22:U 059ef5f0 79e9cc2b mscorwks!Thread::ShouldChangeAbortToUnload+0xe3
23:U 059ef684 79e9cb51 mscorwks!Thread::ShouldChangeAbortToUnload+0x30a
24:U 059ef6c0 79e9ccdd mscorwks!Thread::ShouldChangeAbortToUnload+0x33e
25:U 059ef6e8 79f88128 mscorwks!ManagedThreadBase::KickOff+0x13
26:U 059ef700 79f88202 mscorwks!ThreadNative::KickOffThread+0x269
27:U 059ef79c 79f0e255 mscorwks!Thread::intermediateThreadProc+0x49
28:U 059effc0 77e6482f kernel32!BaseThreadStart+0x34

【问题讨论】:

你在代码中使用了 MUTEX 吗? 【参考方案1】:

在您的代码中搜索死循环,例如重定向到同一页面。

例如

Responce.Redirect("samepage.aspx"); 

Server.Transfer 到同一页面,或类似的东西

protected override void OnLoad(EventArgs e)

  // call by mistake the OnInit and make close loop
  base.OnInit(e);

或者可能是这样的事情,称他为自我并崩溃。

public string Text

   get return Text;
   set Text = value;
 

或对同一页面进行屏幕截图。

【讨论】:

我没有使用 server.transfer 或 asp.net 页面。只是ashx页面。我的猜测是问题发生在我创建的线程中的某个地方,但我真的不知道 @Shay 搜索,正如我所说的,您是上述一种想法。查看您的代码,看看是否有相同的页面一次又一次地调用它们自己的任何点。【参考方案2】:

您是否通过 !CLRStack 遍历了所有托管线程并分析了所有托管调用堆栈?你必须找出每个线程等待的原因,然后找到罪魁祸首。

如果您仍然找不到原因,那么您可以通过http://support.microsoft.com 打开支持案例并与支持人员分享转储。他们拥有找出可能原因的专业知识。

【讨论】:

以上是关于分析 Asp.net 死锁故障转储的主要内容,如果未能解决你的问题,请参考以下文章

如何找到 ASP.Net 网站中的死锁

ASP.NET 挂起 - 通用字典并发问题导致 GC 死锁

如何在 ASP.NET Core 中转储解析的 JWT 令牌?

ASP.NET Core Web API 应用程序是不是可能出现死锁或应用程序挂起状态

ASP.Net 会话状态提供程序故障转移方案

Asp.Net Core App 部署故障示例