.Net 2.0:帮助解决 System.AccessViolationException。 100% 托管代码

发布于 2024-08-06 08:10:48 字数 2392 浏览 6 评论 0原文

这有点重复我之前的问题,尽管我现在问题的目的完全不同了。

我时不时地,大约每周一次,仅在我的开发计算机中,在我制作的网络应用程序中出现 System.AccessViolationException 。

由于我的机器有一些无法正常工作的情况(例如时不时地蓝屏),我之前假设它可能是 RAM 有问题。运行 memtest 24 小时后,我很确定它不是......

所以,情况是这样的:这是一个 wep 应用程序,VB.Net 2.0,100% 托管代码,不使用 COM、Interop 或类似的东西那。它在 Windows Server 2008 SP2 机器上运行。
我正在做的唯一“奇怪”的事情是在应用程序启动时启动我自己的 3 个线程,这些线程在应用程序域内执行“类似 cron ”的操作,并且该应用程序正在处理的大多数请求都是异步处理的,并且许多它们保持打开状态长达 30 秒而无响应。 (我正在进行彗星长轮询)。

另外,我已经研究这个代码大约一年了,大约一个月前才开始这样做。 我想不出我最近更改的整个网络应用程序有什么重大或重要的更改。我几乎全身心投入 Javascript 前端工作。


当异常发生时,我会看到典型的弹出窗口,询问我是否要调试。 当我这样做时,我会看到所有 ASP.Net 线程以及我的 3 个线程。
我的 3 个线程正在调用 Sleep(),这是正常的。所有其他 ASP.Net 线程根本没有调用堆栈。
在 Visual Studio 告诉我出现异常的线程中,我没有看到任何内容。

所以我不确定错误发生在哪里,甚至不知道它是否每次都发生在同一个地方。

我能找到的线索就是“应用程序”事件日志中的这一点:

Faulting application w3wp.exe, version 7.0.6002.18005, time stamp 0x49e03238, 
faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 
0xc0000005, fault offset 0x0000000002358fe8, process id 0x1f4c, application 
start time 0x01ca41395c564ed9.

在那之后,另一个事件与此相关:

An unhandled exception occurred and the process was terminated.

Application ID: DefaultDomain    
Process ID: 6632    
Exception: System.AccessViolationException

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

StackTrace:    at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

我用谷歌搜索了 MgdIndicateCompletion ,但找不到任何真正有用的东西......

有一件事已经改变了一个月前,现在我想起来了,我的开发计算机从 Server 2003 x86 迁移到 Server 2008 x64(因此,IIS6 迁移到 IIS7)。也许这就是原因,但我仍然不确定该怎么做……

我的意思是,这会将问题完全排除在我的代码库之外,对吧?


更新:按照此处的建议,将应用程序池集成“经典”似乎可以解决这个问题。不过,我仍在寻找一个不错的解决方案,或者至少是一个解释。

This is kind of repeated from my previous question, although the objective of my question is completely different now.

I'm getting, now and then, about once a week, only in my development machine, a System.AccessViolationException in a web app I made.

Since my machine is having a few things that don't work quite well (like a blue screen every now and then), I assumed before it might be faulty RAM. After 24 hours running memtest, i'm pretty sure it's not...

So, this is the situation: This is a wep App, VB.Net 2.0, 100% managed code, doesn't use COM, Interop, or anything like that. It's running on a Windows Server 2008 SP2 box.
The only "strange" thing I'm doing is starting 3 threads of my own when the app starts, that do "cron like" stuff inside the appdomain, and also most of the requests this app is handling are handled asynchronously, and many of them are held open without a response for up to 30 seconds. (I'm doing Comet long-polling).

Also, i've been working on this code for about a year now, and it's only started to do this about a month ago.
I can't think of anything major or important that I changed on this whole web app that I changed lately. I've been working almost fully on the Javascript frontend.


When the exception happens, I get the typical popup asking me whether I want to debug.
When I do, I see all the ASP.Net threads plus my 3 threads.
My 3 threads are in a call to Sleep(), which is normal. All the other ASP.Net threads have no call stack at all.
In the thread where Visual Studio tells me I got the exception, I don't see anything.

So I don't know for sure where the error happens, or even whether it happens every time in the same place or not.

All I could find as a clue is this in the "Application" event log:

Faulting application w3wp.exe, version 7.0.6002.18005, time stamp 0x49e03238, 
faulting module unknown, version 0.0.0.0, time stamp 0x00000000, exception code 
0xc0000005, fault offset 0x0000000002358fe8, process id 0x1f4c, application 
start time 0x01ca41395c564ed9.

And right after that, another event with this:

An unhandled exception occurred and the process was terminated.

Application ID: DefaultDomain    
Process ID: 6632    
Exception: System.AccessViolationException

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

StackTrace:    at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
   at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

I've googled MgdIndicateCompletion , but couldn't find anything really useful...

One thing that HAS changed about a month ago, now that I think of it, is that I moved from Server 2003 x86 to Server 2008 x64 (and thus, IIS6 to IIS7) in my dev machine. Maybe that's the cause, but still, i'm not sure what to make of this...

I mean, this would place the problem completely out of my codebase, right?


UPDATE: As suggested here, turning the App Pool integration to "Classic" seems to fix it. I'm still looking for a decent solution, or at least an explanation, though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱人如己 2024-08-13 08:10:48

不了解你的代码,我不知道这有多实用,但是你能注释掉大段代码直到异常不再发生吗?如果可以的话,您也许可以使用二分搜索方法来找出异常的位置发生。

Not knowing your code, I don't know how practical this is, but can you comment-out large swaths of code until the exception no longer happens? If you can, you may be able to use a binary search approach to find out where the exception occurs.

回梦 2024-08-13 08:10:48

检查防病毒软件/病毒是否正在发挥作用。这些程序可能会为每个进程安装错误的挂钩。

Check if antivirus/virus is playing a part. These programs may install faulty hooks to every process.

-小熊_ 2024-08-13 08:10:48

我有一个类似的问题,“故障模块未知”类型崩溃。就我而言,情况恰恰相反,它发生在 SBS 2008 机器上的生产中。我怀疑 Windows 版本有问题,但我不能确定。我已经通过日志记录缩小了范围(这是一项服务,因此我可以写入事件日志),我建议您这是一个选项,可能在

#If DEBUG
    ...
#End If

块内。

您还可以按照 JeffH 的建议仅执行代码的某些部分,也可以使用 DEBUG 测试,以便您仅在生产中执行该代码。

不过,日志记录将是我的起点,因为它可以为您提供有关崩溃发生时刚刚发生的情况的线索。如果只是每隔几天发生一次,那么我将再次仅在您的计算机上写入日志文件,以避免日志文件变大时出现性能问题!

祝你好运...

I have a similar problem with a "faulting module unknown" type crash. In my case, I have the opposite and it's happening in production on an SBS 2008 machine. I am suspicious it's the version of Windows that is the problem, but I can't be sure. I've narrowed it down by logging (it's a service so I'm able to write to the event log) and I would suggest that's an option for you, possibly within

#If DEBUG
    ...
#End If

block.

You could also only execute certain portions of code as suggested by JeffH, also using the DEBUG test so you only execute that code in production.

Logging would be my starting point, though, as it gives you clues as to what's just happened when the crash happens. If it's only every few days it happens, then I'd again only write the log file when on your machine to avoid performance problems if the log file gets big!

Good luck...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文