1

我有一个非常奇怪的问题,正在尝试追踪它。.Net4 中的 Access_Violation。这是我个人认为可能导致异常的事情的一些背景信息。

1)我有一个监控文件的进程,获取文件并使用.net中的SqlBulkCopy将其转储到数据库中。

2)然后,它遍历数据库中的文件记录,完成后将它们标记为已处理,每组记录在多个线程中处理,因为每组可能需要一段时间。处理组后,它会标记通过存储过程处理的组中的那些记录。
2a) 这些组的处理是使用 SqlBulkCopy 并创建一堆用于创建要发送的通知的其他记录。有一堆数据需要添加/转换,因此,我发现 SqlBulkCopy 是迄今为止最快的方法,否则使用 E​​ntityFramework 将这么多数据放入数据库需要很长时间。

3)在从成功生成的通知数据创建通知的线程中,它可以在通知创建之前对部分数据进行加密。

4) 从数据库中删除旧数据。

注意:我的代码使用标准的 .Net4 库并且没有非托管调用。

这些进程都在以系统用户身份运行的 Windows 服务下运行。我试图尽可能详细地描述我的问题,因为似乎没有人遇到过类似的问题。

这是我尝试过但没有成功的事情。
1) 将服务作为控制台应用程序运行。
2)将文件的处理改为单个线程而不是多个线程。
3) 锁定一个对象,防止同时出现多个SqlBulkCopies。
4) 将 WinDbg 附加到进程以尝试捕获异常并找出它崩溃的位置(我无法捕获它)。我尝试使用 WinDbg,因为它看起来应该捕获异常......它没有,也许我错过了加载某些模块,或者告诉捕获/忽略某个异常

这是我的 WinDbg 命令(粗体)及其输出。我对WinDbg了解不多,所以这一切都只是在黑暗中拍摄。

提前感谢您的所有帮助,-Ed-

*This was done right after the service started so I could load the modules and ignore the first chance Access_Violation method*
(fd8.11bc): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`77310530 cc              int     3
0:014> **sxd av**
0:014> **.loadby sos clr**
0:014> **.load c:\debugstuff\psscor4.dll**
0:014> **g**
(fd8.c18): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`77310530 cc              int     3
0:006> **.reload**
Reloading current modules
................................................................
......................
0:006> **g**
(fd8.e24): Access violation - code c0000005 (first chance)
ntdll!NtTerminateProcess+0xa:
00000000`773115da c3              ret
0:009> **!clr**
No export clr found
0:009> **!clrstack**
OS Thread Id: 0xe24 (9)
Unable to walk the managed stack. The current thread is likely not a 
managed thread. You can run !threads to get a list of managed threads in
the process
0:009> **!threads**
ThreadCount:      10
UnstartedThread:  0
BackgroundThread: 9
PendingThread:    0
DeadThread:       0
Hosted Runtime:   no
                                           PreEmptive                                                   Lock
       ID  OSID        ThreadOBJ     State GC       GC Alloc Context                  Domain           Count APT Exception
XXXX    1   d10 000000000057ca00      a020 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA
XXXX    2  149c 0000000000582d40      b220 Enabled  00000000040ce9a0:00000000040d0958 00000000005659c0     0 MTA (Finalizer)
XXXX    3  1294 00000000005a9f30   100a220 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA (Threadpool Worker)
XXXX    7   cbc 000000001a396670   200b220 Enabled  0000000000000000:0000000000000000 00000000005659c0     1 MTA
XXXX    b  173c 000000001a3f22b0   8009220 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA (Threadpool Completion Port)
XXXX    6  1b2c 000000001a3f37e0   1009220 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA (Threadpool Worker)
XXXX    4   ca0 000000001a3f29c0   1009220 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA (Threadpool Worker)
XXXX    a   da0 000000001a3f5420   1009220 Enabled  0000000004120ba8:0000000004122ad8 00000000005659c0     0 MTA (Threadpool Worker)
XXXX    9   b9c 000000001a3f4d10   1009220 Enabled  0000000000000000:0000000000000000 00000000005659c0     0 MTA (Threadpool Worker)
XXXX    8  1194 000000001a3f4600   1009220 Enabled  0000000004134638:0000000004134b38 00000000005659c0     0 MTA (Threadpool Worker)
0:009> **~1**
        ^ Illegal thread error in '~1'
0:009> **~1s**
        ^ Illegal thread error in '~1s'
0:009> **~**
.  9  Id: fd8.e24 Suspend: 0 Teb: 000007ff`ffef6000 Unfrozen
0:009> **~**
.  9  Id: fd8.e24 Suspend: 0 Teb: 000007ff`ffef6000 Unfrozen
0:009> **~#s;~clrstack**
ntdll!NtTerminateProcess+0xa:
00000000`773115da c3              ret
            ^ Syntax error in '~#s;~clrstack'
0:009> **!eestack**
0:009> **~*k**

.  9  Id: fd8.e24 Suspend: 0 Teb: 000007ff`ffef6000 Unfrozen
Child-SP          RetAddr           Call Site
00000000`1a8fe088 00000000`772e418b ntdll!NtTerminateProcess+0xa
00000000`1a8fe090 000007fe`f9ee8552 ntdll!RtlExitUserProcess+0x9b
00000000`1a8fe0c0 000007fe`f9ee83e4 mscoreei!RuntimeDesc::ShutdownAllActiveRuntimes+0x14a
00000000`1a8fe3b0 000007fe`f2ef8787 mscoreei!CLRRuntimeHostInternalImpl::ShutdownAllRuntimesThenExit+0x14
00000000`1a8fe3e0 000007fe`f2ef980c clr!EEPolicy::ExitProcessViaShim+0x88
00000000`1a8fe430 000007fe`f327cd38 clr!SafeExitProcess+0xdc
00000000`1a8fe6e0 000007fe`f30e8114 clr!EEPolicy::HandleFatalError+0x129
00000000`1a8fecc0 000007fe`f2ecb33c clr! ?? ::FNODOBFM::`string'+0xd51f4
00000000`1a8fecf0 000007fe`f2ecb2f2 clr!CLRVectoredExceptionHandlerPhase2+0x2d
00000000`1a8fed40 000007fe`f2ecb1a1 clr!CLRVectoredExceptionHandler+0xaf
00000000`1a8fedb0 00000000`772da59f clr!CLRVectoredExceptionHandlerShim+0x95
00000000`1a8fede0 00000000`772d8e42 ntdll!RtlpCallVectoredHandlers+0xa8
00000000`1a8fee50 00000000`77311278 ntdll!RtlDispatchException+0x22
00000000`1a8ff530 000007fe`f2e35867 ntdll!KiUserExceptionDispatcher+0x2e
00000000`1a8ffaf0 000007fe`f30b5cab clr!WKS::gc_heap::background_sweep+0x5bd
00000000`1a8ffc50 000007fe`f2e33b56 clr! ?? ::FNODOBFM::`string'+0x9f252
00000000`1a8ffca0 00000000`76bf652d clr!WKS::gc_heap::gc_thread_function+0xd3
00000000`1a8ffcd0 00000000`772ec521 KERNEL32!BaseThreadInitThunk+0xd
00000000`1a8ffd00 00000000`00000000 ntdll!RtlUserThreadStart+0x1d
0:009> **analyze -v**
Couldn't resolve error at 'nalyze -v'
0:009> **!analyze -v**
Last event: fd8.e24: Exit process 0:fd8, code 80131506
  debugger time: Fri Aug 17 18:52:01.744 2012 (GMT-6)
0:009> **!analyze -f**
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

Use !analyze -v to get detailed debugging information.

Event is not an exception


Failure could not be analyzed

Last event: fd8.e24: Exit process 0:fd8, code 80131506
  debugger time: Fri Aug 17 18:52:01.744 2012 (GMT-6)
0:009> **.exr 1**
Cannot read Exception record @ 0000000000000001
0:009> **.exr 0**
Cannot read Exception record @ 0000000000000000
0:009> **!dumpstack**
OS Thread Id: 0xe24 (9)
Child-SP         RetAddr          Call Site
000000001a8fe088 00000000772e418b ntdll!NtTerminateProcess+0xa
000000001a8fe090 000007fef9ee8552 ntdll!RtlExitUserProcess+0x9b
000000001a8fe0c0 000007fef9ee83e4 mscoreei!RuntimeDesc::ShutdownAllActiveRuntimes+0x14a
000000001a8fe3b0 000007fef2ef8787 mscoreei!CLRRuntimeHostInternalImpl::ShutdownAllRuntimesThenExit+0x14
000000001a8fe3e0 000007fef2ef980c clr!EEPolicy::ExitProcessViaShim+0x88
000000001a8fe430 000007fef327cd38 clr!SafeExitProcess+0xdc
000000001a8fe6e0 000007fef30e8114 clr!EEPolicy::HandleFatalError+0x129
000000001a8fecc0 000007fef2ecb33c clr! ?? ::FNODOBFM::`string'+0xd51f4
000000001a8fecf0 000007fef2ecb2f2 clr!CLRVectoredExceptionHandlerPhase2+0x2d
000000001a8fed40 000007fef2ecb1a1 clr!CLRVectoredExceptionHandler+0xaf
000000001a8fedb0 00000000772da59f clr!CLRVectoredExceptionHandlerShim+0x95
000000001a8fede0 00000000772d8e42 ntdll!RtlpCallVectoredHandlers+0xa8
000000001a8fee50 0000000077311278 ntdll!RtlDispatchException+0x22
000000001a8ff530 000007fef2e35867 ntdll!KiUserExceptionDispatcher+0x2e
000000001a8ffaf0 000007fef30b5cab clr!WKS::gc_heap::background_sweep+0x5bd
000000001a8ffc50 000007fef2e33b56 clr! ?? ::FNODOBFM::`string'+0x9f252
000000001a8ffca0 0000000076bf652d clr!WKS::gc_heap::gc_thread_function+0xd3
000000001a8ffcd0 00000000772ec521 KERNEL32!BaseThreadInitThunk+0xd
000000001a8ffd00 0000000000000000 ntdll!RtlUserThreadStart+0x1d

我对 WinDbg 非常困惑,只是在黑暗中拍摄希望获得 CLR 堆栈跟踪,但从非托管代码的堆栈跟踪来看,WinDbg 事后抓住了它。

有人对原因和/或解决方法有任何想法吗?或者对从这里去哪里有任何见解?

在 Hans 发表评论之后,这是我对 !VerifyHeap 的结果以及它爆炸的堆转储。

0:000> !VerifyHeap
-verify will only produce output if there are errors in the heap
object 0000000002832a90: does not have valid MT
curr_object:      0000000002832a90
Last good object: 0000000002832a78
----------------
0:000> !do 0x2832a78
Free Object
Size:        24(0x18) bytes
0:000> dc 0x2832a78
00000000`02832a78  0055cd90 00000000 00000000 00000000  ..U.............
00000000`02832a88  0055cd90 00000000 000000b0 00000000  ..U.............
00000000`02832a98  000000a8 000007ff 00000000 00010000  ................
00000000`02832aa8  f2792140 000007fe 00453480 000007ff  @!y......4E.....
00000000`02832ab8  00000000 00010000 f2792140 000007fe  ........@!y.....
00000000`02832ac8  00453758 000007ff 00000000 00010000  X7E.............
00000000`02832ad8  f2792140 000007fe 00453a30 000007ff  @!y.....0:E.....
00000000`02832ae8  00000000 00010000 f2792140 000007fe  ........@!y.....
0:000> d
00000000`02832af8  004534f0 000007ff 00000000 00010000  .4E.............
00000000`02832b08  f2792140 000007fe 0045f2c0 000007ff  @!y.......E.....
00000000`02832b18  00000000 00010000 f2792140 000007fe  ........@!y.....
00000000`02832b28  004b1590 000007ff 000000d8 00000000  ..K.............
00000000`02832b38  ffffff28 ffffffff 00000000 000007ff  (...............
00000000`02832b48  00000000 00000000 f1db6728 000007fe  ........(g......
00000000`02832b58  00000064 00450053 0045004c 00540043  d...S.E.L.E.C.T.
00000000`02832b68  00560020 004c0041 00450055 00440020   .V.A.L.U.E. .D.
4

0 回答 0