简体   繁体   English

使用WinDbg和SOS,死锁或失控线程调试悬挂的.net应用程序?

[英]Debugging hanging .net app with WinDbg and SOS, deadlock or runaway thread?

I am using WinDbg and SOS to debug a hanging .NET application (stays in TaskManager after application is closed). 我正在使用WinDbg和SOS调试一个挂起的.NET应用程序(在应用程序关闭后保留在TaskManager中)。 When I execute the !threads command I get the output below. 当我执行!threads命令时,我得到下面的输出。 It shows only one thread as having a Lock Count = 1. 它仅显示一个线程的Lock Count = 1。

0:002> !threads
ThreadCount:      132
UnstartedThread:  2
BackgroundThread: 54
PendingThread:    0
DeadThread:       48
Hosted Runtime:   no
                                                                                                        Lock  
       ID OSID ThreadOBJ           State GC Mode     GC Alloc Context                  Domain           Count Apt Exception
   0    1 13010 000002716ae37680  2036220 Preemptive  00000271060C1958:00000271060C36E8 000002716ae2afd0 0     STA 
   2    2 106e4 000002716ae63220    2b220 Preemptive  0000027105FB9778:0000027105FBB6E8 000002716ae2afd0 0     MTA (Finalizer) 
XXXX    3    0 000002716d1b8360  8039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Completion Port) 
XXXX    4    0 000002716d1ca8b0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
   7    5 14570 000002716d23e290  3029220 Preemptive  0000027105FF1D08:0000027105FF36E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
  10    7 14c54 000002716d85ddc0  102a220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA (Threadpool Worker) 
  12    8 12758 000002716d8b56a0  202b220 Preemptive  00000271060457C8:00000271060476E8 000002716ae2afd0 1     MTA 
XXXX    9    0 000002716d8795d0  8039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Completion Port) 
  13   10 12ef8 000002716d8b95d0  1020220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  15   11 11e04 000002716d8d21c0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  16   12 14b30 000002716d8dbd50  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  17   14 14760 000002716d819c30  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   15    0 000002716d21c7a0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  18   16 143e8 0000027170b91780  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  19   17 13b9c 0000027170ba5800  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  20   18 11278 0000027170bb8600  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  21   19 14608 000002716d805310  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  22   20 131f8 000002716d8e0830  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  23   21 14a54 000002716d8e1000  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  24   22 13d78 000002716d8e1fa0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  25   23 10da8 000002716d8de8f0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  26   24 137c4 0000027170b99a90  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  27   25 12580 0000027170b9a260  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  28   26 14388 0000027170b9aa30  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  29   27 12390 0000027170b95440  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  30   28 f5b4 0000027170b9b200  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  31   29 fde8 0000027170b963e0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  32   30 13114 0000027170b97380  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  33   31 14068 0000027170b98320  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  34   32 14a38 0000027170ba7790  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  35   33 1391c 0000027170ba67f0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  36   34 13a64 0000027170ba6fc0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  37   35 f764 0000027170bac5b0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  38   36 f818 0000027170baae40  1029220 Preemptive  0000027106299D48:000002710629B6E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
  39   37 14738 0000027170bacd80  1029220 Preemptive  0000027106275548:00000271062756E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX   38    0 0000027170ba7f60  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  40   39 1232c 0000027170ba6020  3029220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX   40    0 0000027170db57e0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX   41    0 0000027170db5010  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX   42    0 0000027170db7720  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  42   43 14d6c 0000027170db4840  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  43   44 13d70 0000027170db1960  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   45    0 0000027170db2130    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX   46    0 0000027170db4070    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX   47    0 00000271731b4650    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  44   48 60ec 00000271731b0fa0    2b020 Preemptive  000002710617F738:00000271061816E8 000002716ae2afd0 0     MTA 
  45   49 132d8 00000271731b36b0  202b020 Preemptive  000002710617D738:000002710617F6E8 000002716ae2afd0 0     MTA 
  46   50 134cc 00000271731b1770  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  47   51 14028 00000271731b2ee0  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   52    0 00000271731b3e80    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX   53    0 00000271731b1f40    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  48   54 14bf0 00000271731b07d0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  49   55 1147c 00000271731c8800  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  50   56 1467c 00000271731c8030    2b020 Preemptive  0000027106185738:00000271061876E8 000002716ae2afd0 0     MTA 
  51   57 14148 00000271731cbeb0  202b020 Preemptive  0000027106183738:00000271061856E8 000002716ae2afd0 0     MTA 
  52   58 14574 00000271731cc680  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  53   59 12444 00000271731c5920  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   60    0 00000271731c7090    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX   61    0 00000271731c8fd0     9600 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX   62    0 00000271731c7860     9600 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  54   63 14904 00000271731c97a0  202b220 Preemptive  0000027106359808:000002710635B6E8 000002716ae2afd0 0     MTA 
  55   64 12920 00000271731f67c0    2b020 Preemptive  000002710634F700:00000271063516E8 000002716ae2afd0 0     MTA 
  56   65 14e54 00000271731f5050  202b020 Preemptive  0000027106189738:000002710618B6E8 000002716ae2afd0 0     MTA 
  57   66 14e34 00000271731fb5e0  202b020 Preemptive  0000027106354F28:00000271063556E8 000002716ae2afd0 0     MTA 
  58   67 11d88 00000271731fa640  202b020 Preemptive  00000271060797D8:000002710607B6E8 000002716ae2afd0 0     MTA 
XXXX   68    0 00000271731fae10    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  60   69 12d2c 00000271731fbdb0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   70    0 00000271731f9e70    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  59   71 12e5c 00000271731f8ed0    2b020 Preemptive  0000027106193738:00000271061956E8 000002716ae2afd0 0     MTA 
  61   72 14a94 000002717320c730  202b020 Preemptive  0000027106191738:00000271061936E8 000002716ae2afd0 0     MTA 
  62   73 fd58 0000027173213f70  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  63   74 13858 0000027173212030  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  64   75 ef34 00000271732185c0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   76    0 00000271732156e0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  65   77 fd9c 0000027173216680  202b220 Preemptive  0000027106094C80:00000271060956E8 000002716ae2afd0 0     MTA 
  66   78 129a4 0000027173217620  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   79    0 0000027173211090    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  67   80 13120 0000027173209080  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  68   81 147ec 000002717320fde0  202b220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   82    0 000002717320a7f0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  69   83 12720 000002717320bf60    2b020 Preemptive  000002710619D738:000002710619F6E8 000002716ae2afd0 0     MTA 
  70   84 f42c 000002717320cf00    2b020 Preemptive  0000027106199738:000002710619B6E8 000002716ae2afd0 0     MTA 
  71   85 148a0 000002717320ee40    2b020 Preemptive  00000271061A1738:00000271061A36E8 000002716ae2afd0 0     MTA 
  72   86 14f50 000002717320dea0  202b020 Preemptive  0000027106197738:00000271061996E8 000002716ae2afd0 0     MTA 
  73   87 14690 000002717320e670  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  74   88 13dd0 0000027173256850  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  75   89 13adc 0000027173257020  202b020 Preemptive  000002710619B738:000002710619D6E8 000002716ae2afd0 0     MTA 
  76   90 13668 0000027173254910  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  77   91 14d78 0000027173258f60  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  78   92 12f54 00000271732558b0  202b020 Preemptive  000002710619F738:00000271061A16E8 000002716ae2afd0 0     MTA 
  79   93 13e38 0000027173252200  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
  80   94 14938 0000027173251a30  202b020 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     MTA 
XXXX   95    0 000002717325a6d0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  81   96 14064 000002717325aea0    27220 Preemptive  0000027106361B90:00000271063636E8 000002716ae2afd0 0     STA 
  82   97 11fb8 000002717325c610    27220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     STA 
XXXX   98    0 000002717325d5b0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  83   99 13580 000002717325e550  8029220 Preemptive  00000271062F4B28:00000271062F56E8 000002716ae2afd0 0     MTA (Threadpool Completion Port) 
XXXX  100    0 0000027173258790  8039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Completion Port) 
   8  101 7e2c 000002717325fcc0    20220 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  102    0 000002717325dd80    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  103    0 0000027173260490    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  104    0 000002716aea61b0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  105    0 000002717343f830    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  106    0 0000027173440000    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
  84  107 13848 0000027173444650  1029220 Preemptive  00000271062F2720:00000271062F36E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX  108    0 0000027173440fa0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  109    0 0000027173441f40  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  110    0 0000027173442710  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  111    0 0000027173444e20  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  112    0 00000271734484d0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  113    0 0000027173448ca0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  114    0 0000027173446d60  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  115    0 0000027173447530  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  85  116 13ec8 0000027173449470  1029220 Preemptive  000002710624CFB8:000002710624D6E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX  117    0 00000271734436b0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  118    0 0000027173447d00  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  119    0 000002717344dac0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  86  120 137a8 000002717344c350  1029220 Preemptive  0000027106258D60:00000271062596E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX  121    0 000002717344d2f0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  122    0 0000027173326f50  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
XXXX  123    0 0000027173327ef0  1039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Worker) 
  87  124 1443c 00000271733286c0  1029220 Preemptive  000002710631AEF8:000002710631B6E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
  88  125 13b98 0000027173329660  1029220 Preemptive  0000027106256958:00000271062576E8 000002716ae2afd0 0     MTA (Threadpool Worker) 
XXXX   13    0 000002717332bd70    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  126    0 000002717332d4e0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  127    0 00000271733332a0    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  128    0 0000027173331b30    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX  129    0 0000027173332300    39820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn 
XXXX    6    0 000002717332f420  8039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Completion Port) 
XXXX  131    0 000002717332e480  8039820 Preemptive  0000000000000000:0000000000000000 000002716ae2afd0 0     Ukn (Threadpool Completion Port) 
  89  130 1404c 0000027173332ad0  8029220 Preemptive  0000027106334438:00000271063356E8 000002716ae2afd0 0     MTA (Threadpool Completion Port) 
  90  132 14cbc 000002717332dcb0  8029220 Preemptive  000002710635C790:000002710635D6E8 000002716ae2afd0 0     MTA (Threadpool Completion Port) 

When I execute !syncblk I get the following output which, I believe, tells me that there are no threads that own any monitors: 当我执行!syncblk时,我得到以下输出,我相信这告诉我,没有线程拥有任何监视器:

0:002> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
-----------------------------
Total           351
CCW             49
RCW             15
ComClassFactory 0
Free            35

When I switch to the thread that shows the lock I see the following: 当我切换到显示锁的线程时,会看到以下内容:

0:002> ~12s
ntdll!NtWaitForMultipleObjects+0x14:
00007ffe`7b5b6c24 c3              ret

When I execure !runaway I have this: 当我执行!runaway时,我有这个:

 0:000> !runaway
 User Mode Time
  Thread       Time
    0:13010     0 days 0:00:16.203
    6:e444     0 days 0:00:01.687
   81:14064     0 days 0:00:00.281
   40:1232c     0 days 0:00:00.234
   16:14b30     0 days 0:00:00.125
   32:13114     0 days 0:00:00.078
   65:fd9c     0 days 0:00:00.062
   39:14738     0 days 0:00:00.062
   67:13120     0 days 0:00:00.046
   38:f818     0 days 0:00:00.046
   54:14904     0 days 0:00:00.031
    7:14570     0 days 0:00:00.031
   87:1443c     0 days 0:00:00.015
   58:11d88     0 days 0:00:00.015
   48:14bf0     0 days 0:00:00.015
   44:60ec     0 days 0:00:00.015
   42:14d6c     0 days 0:00:00.015
   27:12580     0 days 0:00:00.015
   15:11e04     0 days 0:00:00.015
    2:106e4     0 days 0:00:00.015
   91:149e8     0 days 0:00:00.000
   90:14cbc     0 days 0:00:00.000
   89:1404c     0 days 0:00:00.000
   88:13b98     0 days 0:00:00.000
   86:137a8     0 days 0:00:00.000
   85:13ec8     0 days 0:00:00.000
   84:13848     0 days 0:00:00.000
   83:13580     0 days 0:00:00.000
   82:11fb8     0 days 0:00:00.000
   80:14938     0 days 0:00:00.000
   79:13e38     0 days 0:00:00.000
   78:12f54     0 days 0:00:00.000
   77:14d78     0 days 0:00:00.000
   76:13668     0 days 0:00:00.000
   75:13adc     0 days 0:00:00.000
   74:13dd0     0 days 0:00:00.000
   73:14690     0 days 0:00:00.000
   72:14f50     0 days 0:00:00.000
   71:148a0     0 days 0:00:00.000
   70:f42c     0 days 0:00:00.000
   69:12720     0 days 0:00:00.000
   68:147ec     0 days 0:00:00.000
   66:129a4     0 days 0:00:00.000
   64:ef34     0 days 0:00:00.000
   63:13858     0 days 0:00:00.000
   62:fd58     0 days 0:00:00.000
   61:14a94     0 days 0:00:00.000
   60:12d2c     0 days 0:00:00.000
   59:12e5c     0 days 0:00:00.000
   57:14e34     0 days 0:00:00.000
   56:14e54     0 days 0:00:00.000
   55:12920     0 days 0:00:00.000
   53:12444     0 days 0:00:00.000
   52:14574     0 days 0:00:00.000
   51:14148     0 days 0:00:00.000
   50:1467c     0 days 0:00:00.000
   49:1147c     0 days 0:00:00.000
   47:14028     0 days 0:00:00.000
   46:134cc     0 days 0:00:00.000
   45:132d8     0 days 0:00:00.000
   43:13d70     0 days 0:00:00.000
   41:14504     0 days 0:00:00.000
   37:f764     0 days 0:00:00.000
   36:13a64     0 days 0:00:00.000
   35:1391c     0 days 0:00:00.000
   34:14a38     0 days 0:00:00.000
   33:14068     0 days 0:00:00.000
   31:fde8     0 days 0:00:00.000
   30:f5b4     0 days 0:00:00.000
   29:12390     0 days 0:00:00.000
   28:14388     0 days 0:00:00.000
   26:137c4     0 days 0:00:00.000
   25:10da8     0 days 0:00:00.000
   24:13d78     0 days 0:00:00.000
   23:14a54     0 days 0:00:00.000
   22:131f8     0 days 0:00:00.000
   21:14608     0 days 0:00:00.000
   20:11278     0 days 0:00:00.000
   19:13b9c     0 days 0:00:00.000
   18:143e8     0 days 0:00:00.000
   17:14760     0 days 0:00:00.000
   14:13e34     0 days 0:00:00.000
   13:12ef8     0 days 0:00:00.000
   12:12758     0 days 0:00:00.000
   11:13e40     0 days 0:00:00.000
   10:14c54     0 days 0:00:00.000
    9:13e98     0 days 0:00:00.000
    8:7e2c     0 days 0:00:00.000
    5:14b18     0 days 0:00:00.000
    4:14a48     0 days 0:00:00.000
    3:12da4     0 days 0:00:00.000
    1:14fd8     0 days 0:00:00.000

I am not an expert in WinDbg or SOS, but can someone interpret this for me? 我不是WinDbg或SOS方面的专家,但是有人可以帮我解释一下吗? I think the problem is not a deadlock, but maybe a runaway thread. 我认为问题不在于僵局,而在于线程失控。 How do I proceed. 我该如何进行。 I am stuck at this point. 我被困在这一点上。

Thanks! 谢谢!

You have a lot of foreground threads in that list and any foreground thread still running will prevent the CLR from shutting down even if the app doesn't have any visible windows according to Microsoft's docs . 根据Microsoft的文档 ,该列表中有很多前台线程,并且即使应用程序没有任何可见窗口,任何仍在运行的前台线程仍将阻止CLR关闭。

The way you can tell which ones are not background is !ThreadState command, for example: 您可以分辨出哪些不是背景的方法是!ThreadState命令,例如:

0:000> !threadstate 2b020
    Legal to Join
    CLR Owns
    CoInitialized
    In Multi Threaded Apartment
    Fully initialized

Use the value from the State column of !threads output as a parameter. !threads输出的“ State列中的值用作参数。

Back to your list, all threads having state of 2b020 or 202b020 are foreground. 回到您的列表,所有状态为2b020或202b020的线程都是前台。 Check their stacks to tie them to where you create them in your code. 检查它们的堆栈,以将它们绑定到在代码中创建它们的位置。

Make them background by setting IsBackground property to true when you create them. 通过在创建它们时将IsBackground属性设置为true来使其成为背景。 Better yet, don't create them. 更好的是,不要创建它们。 Here's a good list of alternatives: Background Thread? 这是一个不错的选择列表: 后台线程? Let me count the ways.... 让我来计算一下....

Unlike C++, threads in .NET will by default keep the application alive even if the main thread runs to the end of the main() method. 与C ++不同,即使主线程运行到main()方法的末尾,.NET中的线程在默认情况下也会使应用程序保持活动状态。 This means that all other threads in your application need to reach their end, too. 这意味着应用程序中的所有其他线程也需要到达末尾。

Of course, there are exceptions to this rule: 当然,此规则也有例外:

  • " background " threads will be terminated 后台 ”线程将终止
  • you don't need to care about garbage collector and finalizer threads 您不需要关心垃圾收集器和终结器线程
  • .NET will care about threadpool threads .NET将关心线程池线程
  • (potentially others) (可能是其他人)

If you say "I knew all that and considered it", that's fine. 如果您说“我知道所有并考虑了”,那很好。 There are plenty XXXX threads, which is an indicator that these threads died. XXXX线程很多,这表明这些线程已死亡。 And that's good, if you want the app to shut down. 如果您想关闭应用程序,那就很好。

So there may be a deadlock in the remaining threads. 因此,其余线程可能会出现死锁。 A deadlock may occur with any synchronization object, not just the lock statement. 任何同步对象都可能发生死锁,而不仅仅是lock语句。 In .NET we have many: 在.NET中,我们有很多:

  • lock statement lock声明
  • Monitor (essentially the same) Monitor (基本上相同)
  • ReaderWriterLock
  • ReaderWriterLockSlim
  • Process
  • Thread
  • SpinLock
  • CountDownEvent
  • ... ...

And, even worse, using P/Invoke, we can access all the native synchronization objects, too: 而且,更糟糕的是,使用P / Invoke,我们也可以访问所有本机同步对象:

  • Mutex
  • Semaphore
  • Event
  • WaitableTimer
  • CriticalSection
  • Job
  • ... ...

Problem is: all these synchronization objects make debugging a deadlock quite complex. 问题是:所有这些同步对象使调试死锁变得非常复杂。 Positive side is: you have all the time you want, because the application waits for you to analyze it. 积极的一面是:您拥有所有想要的时间,因为应用程序等待您对其进行分析。

My suggestions for a deadlock analysis: 我对死锁分析的建议:

  1. Take a crash dump . 进行故障转储 Many developers don't know that a crash dump is still helpful even if the application did not crash . 许多开发人员不知道即使应用程序没有崩溃 ,崩溃转储仍然有用。 It's helpful in case of spontaneous reboots of your PC, like Windows installing updates. 如果您的PC自发重启,例如Windows安装更新,这将很有帮助。
  2. In case of .NET, run !dlk . 如果是.NET,请运行 !dlk It's a specialized command for deadlocks and considers the lock statement, Monitor , ReaderWriterLock and native CriticalSection . 这是一个用于死锁的专用命令,并考虑lock语句MonitorReaderWriterLock和本机CriticalSection That's a big time saver. 节省大量时间。
  3. !analyze -hang is quite good in giving you the starting point of your analysis. !analyze -hang可以很好地为您提供分析的起点。 It often does not figure out the whole wait chain, but a good starting point is crucial. 它通常无法弄清整个等待链,但是一个良好的起点至关重要。

If you're concerned about "runaway" threads, then a live application is much better. 如果您担心“失控”线程,那么实时应用程序会更好。 The active thread should consume CPU which you can see in tools like Process Explorer . 活动线程应该消耗CPU,您可以在Process Explorer之类的工具中看到该CPU。 Do the following: 请执行下列操作:

  1. Configure the symbols if you like to see good call stacks right away 如果您希望立即看到良好的调用堆栈,请配置符号
  2. Open the properties of the affected process 打开受影响过程的属性
  3. Navigate to the "Threads" tab 导航到“线程”选项卡
  4. Watch out for a thread which has a lot of "Cycles Delta". 注意具有很多“循环增量”的线程。 The tool will give you the thread ID of that thread. 该工具将为您提供该线程的线程ID。

In such a case, you'll need to figure out how to either cancel the operation the thread is working on or display a progress bar for the user to determine when the program will terminate. 在这种情况下,您将需要弄清楚如何取消线程正在执行的操作,或者显示进度条以供用户确定程序何时终止。

Assuming you waited more than 16 seconds for the program to terminate, a runaway thread is likely not your issue. 假设您等待了16秒钟以上的程序终止,那么线程失控可能不是您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM