应用程序挂起而不等待线程

时间:2014-03-13 15:06:30

标签: c# .net visual-studio debugging windbg

我有一个.NET x64 .NET 4巨大的应用程序。那个app使用不同的其他模块。应用程序挂起(显示“未响应”标题)。我有完整的资源(例如3d party,NHibernate除外)。但是,由于在附加Managed和Native支持期间“64位调试操作花费的时间超出预期”,我无法使用Visual Studio 2012。如果我只在托管模式下使用附加都很好,但是没有断点(“Debug-> break”不起作用)。所以我看不到调用堆栈,了解问题。

我使用Process Explorer完全转储了我的应用程序,并开始使用WinDbg x64来处理它。

!threads
ThreadCount:      40
UnstartedThread:  0
BackgroundThread: 38
PendingThread:    0
DeadThread:       0
Hosted Runtime:   no
                                                                                                    Lock  
   ID OSID ThreadOBJ           State GC Mode     GC Alloc Context                  Domain           Count Apt Exception
0    1 4030 0000000001f7c0d0    26020 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     STA 
2    2 4750 0000000001f87ee0    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Finalizer) 
4    6 116c 000000001b88c600  1020220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     Ukn (Threadpool Worker) 
13   11  5ac 0000000021a19ef0  102a220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
15   12 4440 0000000021a1a6c0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
16   10 1774 0000000021a1c600  1029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
17    7 3680 0000000021a1be30  3029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
18    9 1854 0000000021a1b660    2b020 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
19    4 4b5c 0000000021a1d5a0  3029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
20   14 4918 0000000021a1e540  3029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
21   15 2398 0000000021a1ed10  3029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
22   17 1c84 0000000021a1fcb0    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
23   20 3368 0000000021a21420    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
24   19 2d10 0000000021e09cd0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
25   22 4200 0000000021e0a4a0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
26   24 45e0 0000000021e0b440  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
27   25 3478 0000000021e0bc10    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA (GC) 
28   26 2ad8 0000000021e0c3e0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
29   28 493c 0000000021e0d380  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
30   30 23c4 0000000021e0e320    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
31   18 13b4 0000000021a20480  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
32   31 4aa4 0000000021a20c50    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
33   32 4890 0000000021e0eaf0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
34   33 238c 0000000021e0f2c0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
35   34 4a1c 0000000021e0fa90    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
36   36 3c78 0000000021e10a30    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
37   35 2cf8 0000000021e10260    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
38   37 4bbc 00000000220b6690  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
39   39 2e58 00000000220b7630    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
40   43 3b0c 00000000221dfda0    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 2     MTA 
41   44 2f60 00000000221e0570    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
42   45 49f8 00000000221e0d40  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
43   48 3080 00000000221e24b0  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
44   13 2818 0000000034967040    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
45    8 331c 0000000034965100  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
46   46 3fd8 0000000021a1ae90    2b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 1     MTA 
47   41 301c 0000000034964930  202b220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA 
48   21 412c 00000000349658d0  1029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Worker) 
49    3 49bc 0000000034966870  8029220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     MTA (Threadpool Completion Port) 
50   42 1c9c 0000000034964160  1039220 Preemptive  0000000000000000:0000000000000000 0000000001f6d990 0     Ukn (Threadpool Worker) 


!syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
851 000000001ba1e388            7         1 00000000221dfda0 3b0c  40   000000000a2344b0 System.Object
899 000000001ba1cc78           21         1 0000000021e10260 2cf8  37   000000000b03ed90 System.Object
-----------------------------
Total           1266
CCW             72
RCW             2
ComClassFactory 0
Free            647

据我了解,有两个锁。但是没有像herehere这样的等待线程 调用此线程的堆栈:

0:040> ~40 kb
RetAddr           : Args to Child                                                           : Call Site
000007fe`fd9710dc : 000007fe`ed1dfdb0 00000000`221dfda0 00000000`00000000 000007fe`f2181352 : ntdll!NtWaitForSingleObject+0xa
000007fe`f1f6839f : 00000000`00000000 00000000`000000f4 00000000`00000000 00000000`000000f4 : KERNELBASE!WaitForSingleObjectEx+0x79
000007fe`f1f68357 : 00000000`00000000 00000000`00000000 000007fe`ed7e92b8 00000000`00000000 : clr!CLREventBase::WaitEx+0x16c
000007fe`f1f68318 : 000007fe`ed7ca730 000007fe`f1f649d4 000007fe`ed1dfdb0 00000000`00000058 : clr!CLREventBase::WaitEx+0x103
000007fe`f2085e6e : 00000000`00000000 00000000`375a9340 00000000`00000000 00000000`00000006 : clr!CLREventBase::WaitEx+0x70
000007fe`f1f71891 : 00000000`00000000 00000000`123b1050 00000000`00000000 000007fe`ed7e92b8 : clr!WKS::GCHeap::WaitUntilGCComplete+0x2b
000007fe`f1f6e6a9 : 00000000`221dfda0 00000000`00000000 00000000`00000000 00000000`02f7db50 : clr!Thread::RareDisablePreemptiveGC+0x17f
000007fe`ed67b942 : 000007fe`ed67b920 000007fe`ed115a60 00000000`60800000 000007fe`f203becc : clr!JIT_RareDisableHelper+0x4d

0:040> ~40 e !CLRStack
OS Thread Id: 0x3b0c (40)
    Child SP               IP Call Site
00000000375a9508 0000000077a212fa [InlinedCallFrame: 00000000375a9508] System.Globalization.CompareInfo.InternalFindNLSStringEx(IntPtr, IntPtr, System.String, Int32, System.String, Int32, Int32, System.String, Int32)
00000000375a9508 000007feed67b920 [InlinedCallFrame: 00000000375a9508] System.Globalization.CompareInfo.InternalFindNLSStringEx(IntPtr, IntPtr, System.String, Int32, System.String, Int32, Int32, System.String, Int32)
00000000375a94b0 000007feed67b920 DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, System.String, Int32, System.String, Int32, Int32, System.String, Int32)
00000000375a95e0 000007feed669cc0 System.Globalization.CompareInfo.LastIndexOf(System.String, System.String, Int32, Int32, System.Globalization.CompareOptions)
00000000375a9680 000007feed674a9a System.String.LastIndexOf(System.String, Int32, Int32, System.StringComparison)
00000000375a96e0 000007feed5acd1c System.RuntimeType.SplitName(System.String, System.String ByRef, System.String ByRef)
00000000375a9740 000007feed635283 System.RuntimeType.GetInterface(System.String, Boolean)
00000000375a97d0 000007feed5f5ec4 System.Security.PermissionToken.FindToken(System.Type)
00000000375a9850 000007feed63c8b9 System.Security.PermissionSet.RemovePermissionImpl(System.Type)
00000000375a9890 000007feed63d472 System.Security.PermissionSet.CopyWithNoIdentityPermissions()
00000000375a98d0 000007feed5f5dbc System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32, System.Security.PermissionSet, System.Threading.CompressedStack)
00000000375a9b90 000007fef1fc9e03 [GCFrame: 00000000375a9b90] 
00000000375abcd8 000007fef1fc9e03 [InlinedCallFrame: 00000000375abcd8] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000000375abcd8 000007feedda5a72 [InlinedCallFrame: 00000000375abcd8] System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(System.IRuntimeMethodInfo)
00000000375abcb0 000007feedda5a72 DomainNeutralILStubClass.IL_STUB_PInvoke(System.IRuntimeMethodInfo)
00000000375abd70 000007feee005d19 System.Reflection.Emit.DynamicMethod.CreateDelegate(System.Type, System.Object)
00000000375abdc0 000007fed8d2623a System.Linq.Expressions.Compiler.LambdaCompiler.Compile(System.Linq.Expressions.LambdaExpression, System.Runtime.CompilerServices.DebugInfoGenerator)
00000000375abe10 000007fe93778d12 Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.EvaluateSubtree(System.Linq.Expressions.Expression)
00000000375abe60 000007fe93778b5d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375abed0 000007fe937788a9 Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitBinaryExpression(System.Linq.Expressions.BinaryExpression)
00000000375abf40 000007fe93778b4d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375abfb0 000007fe9376a673 Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitLambdaExpression(System.Linq.Expressions.LambdaExpression)
00000000375ac020 000007fe93778b4d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375ac090 000007fe9376a55c Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitUnaryExpression(System.Linq.Expressions.UnaryExpression)
00000000375ac0e0 000007fe93778b4d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375ac150 000007fe9376a39e Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitAndConvert[[System.__Canon, mscorlib]](System.__Canon, System.String)
00000000375ac190 000007fe9376a137 Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitList[[System.__Canon, mscorlib]](System.Collections.ObjectModel.ReadOnlyCollection`1<System.__Canon>, System.Func`2<System.__Canon,System.__Canon>)
00000000375ac1f0 000007fe93769def Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitMethodCallExpression(System.Linq.Expressions.MethodCallExpression)
00000000375ac250 000007fe93778b4d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375ac2c0 000007fe9376a39e Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitAndConvert[[System.__Canon, mscorlib]](System.__Canon, System.String)
00000000375ac300 000007fe9376a137 Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitList[[System.__Canon, mscorlib]](System.Collections.ObjectModel.ReadOnlyCollection`1<System.__Canon>, System.Func`2<System.__Canon,System.__Canon>)
00000000375ac360 000007fe93769def Remotion.Linq.Parsing.ExpressionTreeVisitor.VisitMethodCallExpression(System.Linq.Expressions.MethodCallExpression)
00000000375ac3c0 000007fe93778b4d Remotion.Linq.Parsing.ExpressionTreeVisitors.PartialEvaluatingExpressionTreeVisitor.VisitExpression(System.Linq.Expressions.Expression)
00000000375ac430 000007fe937692a8 NHibernate.Linq.NhLinqExpression..ctor(System.Linq.Expressions.Expression, NHibernate.ISessionFactory)
00000000375ac490 000007fe9376919f NHibernate.Linq.DefaultQueryProvider.Execute(System.Linq.Expressions.Expression)
00000000375ac4f0 000007fe937690fa NHibernate.Linq.DefaultQueryProvider.Execute[[System.__Canon, mscorlib]](System.Linq.Expressions.Expression)
00000000375ac520 000007fe93769083 Remotion.Linq.QueryableBase`1[[System.__Canon, mscorlib]].GetEnumerator()
00000000375ac570 000007feed590b6e System.Collections.Generic.List`1[[System.__Canon, mscorlib]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
00000000375ac5e0 000007fed8d18df0 System.Linq.Enumerable.ToList[[System.__Canon, mscorlib]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
... my code ...

0:037> ~37 kb
RetAddr           : Args to Child                                                           : Call Site
000007fe`fd9710dc : 06000000`00000001 04000000`00000000 00000000`21e10260 000007fe`00000000 : ntdll!NtWaitForSingleObject+0xa
000007fe`f1f6839f : 00000000`00000000 00000000`000000f4 00000000`00000000 00000000`000000f4 : KERNELBASE!WaitForSingleObjectEx+0x79
000007fe`f1f68357 : 00000000`00000000 00000000`00000000 00000000`22c5ed58 000007fe`ed64799b : clr!CLREventBase::WaitEx+0x16c
000007fe`f1f68318 : 00000000`22c5be50 00000000`00000000 000007fe`ed7e1458 00000000`22c5c010 : clr!CLREventBase::WaitEx+0x103
000007fe`f2085e6e : 00000000`00000000 00000000`22c5be70 00000000`00000000 00000000`00000006 : clr!CLREventBase::WaitEx+0x70
000007fe`f1f71891 : 00000000`00000000 00000000`00000000 00000000`00000070 ffffffff`ffffffff : clr!WKS::GCHeap::WaitUntilGCComplete+0x2b
000007fe`f2163733 : 00000000`21e10260 00000000`00000000 00000000`00004e20 00000000`08452ee0 : clr!Thread::RareDisablePreemptiveGC+0x17f
000007fe`f2166aa8 : 06000000`00000001 00000000`00004e20 04000000`00000001 000007fe`f2166a10 : clr! ?? ::FNODOBFM::`string'+0x4998e
000007fe`94555cf5 : 00000000`00004e20 00000000`02643368 00000000`00000000 00000000`0a27ab00 : clr!ThreadNative::Sleep+0x98


0:037> ~37 e !CLRStack
OS Thread Id: 0x2cf8 (37)
    Child SP               IP Call Site
0000000022c5bf48 0000000077a212fa [HelperMethodFrame: 0000000022c5bf48] System.Threading.Thread.SleepInternal(Int32)
... my code ...

线程0:

0:000> ~0 kb
RetAddr           : Args to Child                                                           : Call Site
000007fe`fd9710dc : 00000000`0015e6a0 00000000`001415a0 00000000`00000200 00000000`00000000 : ntdll!NtWaitForSingleObject+0xa
000007fe`f1f6839f : 00000000`00000000 00000000`000000f4 00000000`00000000 00000000`000000f4 : KERNELBASE!WaitForSingleObjectEx+0x79
000007fe`f1f68357 : 00000000`00000000 00000000`00000000 00000000`00000000 00000001`8004ee55 : clr!CLREventBase::WaitEx+0x16c
000007fe`f1f68318 : 00000000`001415a0 ffffffff`e45f4ebf 000007ff`fffde000 00000000`00000200 : clr!CLREventBase::WaitEx+0x103
000007fe`f2085e6e : 00000000`00000000 00000000`0015e930 00000000`00000000 00000000`00000006 : clr!CLREventBase::WaitEx+0x70
000007fe`f1f71891 : 00000000`00000001 00000000`00000000 00000000`00000000 00000000`00000000 : clr!WKS::GCHeap::WaitUntilGCComplete+0x2b
000007fe`f1f6e6a9 : 00000000`01f7c0d0 00000000`00000000 00000000`00000000 00000000`00000001 : clr!Thread::RareDisablePreemptiveGC+0x17f
000007fe`da0f0973 : 00000000`024022e8 00000000`801c4800 00000000`00000000 00000000`02640720 : clr!JIT_RareDisableHelper+0x4d
000007fe`da0efecc : 00000000`03917e18 00000000`00000001 00000000`ffffffff 00000000`00000000 : System_Windows_Forms_ni+0x310973
000007fe`da0ef87f : 00000000`024022e8 00000000`ffffffff 00000000`0390f8d0 00000000`00000000 : System_Windows_Forms_ni+0x30fecc
000007fe`9291012f : 00000000`024037b8 00000000`ffffffff 00000000`03d85610 00000000`01f7c0d0 : System_Windows_Forms_ni+0x30f87f
000007fe`f1fc9e03 : 00000000`00000000 00000000`0015f3f0 000007fe`f20916d5 00000000`00000001 : 0x000007fe`9291012f
000007fe`f1fc9e7e : 00000000`00000000 00000000`00000003 00000000`01fb0f30 00000000`000006fc : clr!CallDescrWorkerInternal+0x83
000007fe`f1fc9ef0 : 00000000`00000000 00000000`00000007 00000000`0015f1d0 00000000`0015f288 : clr!CallDescrWorkerWithHandler+0x4a
000007fe`f20c2a7e : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : clr!MethodDescCallSite::CallTargetWorker+0x2e2
000007fe`f20c31d6 : 00000000`00000000 00000000`00000001 00000000`00000000 00000000`00000000 : clr!RunMain+0x1e7

0:000> ~0 e !CLRStack
OS Thread Id: 0x4030 (0)
    Child SP               IP Call Site
000000000015eb10 0000000077a212fa [InlinedCallFrame: 000000000015eb10] System.Windows.Forms.UnsafeNativeMethods.WaitMessage()
000000000015eb10 000007feda0f0954 [InlinedCallFrame: 000000000015eb10] System.Windows.Forms.UnsafeNativeMethods.WaitMessage()
000000000015eaa0 000007feda0f0954 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
000000000015eca0 000007feda0efecc System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
000000000015edf0 000007feda0ef87f System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
... my code ...

感谢DebugDiag我发现了一个问题(看起来像是一个问题)

  

GC正在此过程中运行。触发GC的线程是27。

     

应用程序的以下主题(0 16 18 22 23 30 32 35 36 37 39 40 41 44 46 48 49 50)正在等待.net垃圾回收完成。线程27触发了垃圾收集。

     

以下应用程序的线程正在等待进入.NET Lock(24 25 26 28 29 31 33 34 38 42 43 45 47)查看线程37的callstack以查看为什么该线程id在等待以及为什么它是没有释放锁。

     

在线程27拥有的0x0023fef0处检测到可能阻塞或泄漏的关键部分

     

以下应用程序线程正在System.Threading.Monitor.Wait(17 19 20 21)中等待

     

以下应用程序线程正在等待WaitOne(15)

线程27:http://pastebin.com/GS0r8hi7

我尝试使用SOSEx!dlk命令,发现没有死锁。 我接下来需要做什么?

0 个答案:

没有答案