简体   繁体   中英

ASP.NET / IIS6: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

I'm getting the following error on my production servers:

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

It doesn't happen all the time, but seems to happen most frequently during times of high traffic.

The error is occurring in a custom IHttpHandler .

The stack trace doesn't give much of an indication of what's actually going on when the exception happens - all that is happening in the area it indicates is writing to the response using Response.Write.

I've noticed that when this starts happening, if I remove the traffic from the server, recycle the app pool, and put it back on, it seems to help. Though, when the traffic is first returned, there is a cluster of these errors before it begins working properly.

I've also taken a look through the dozens of other SO questions/ google search results with this error, but none of the remedies seem to be relevant to this situation.

Edit: I don't do anything directly with unmanaged/unsafe code. I do use MEF though, and I'm not sure if it does.

No, this is not a serverfault issue. It's clearly a programming issue.

What is that IHttpHandler code actually doing? Is it interacting with any unmanaged code?

BTW, the exception message means what it said.

Is your custom handler managed? This message usually indicates that the problem is with the unmanaged code - corrupted pointers and the such.

I have seen this occur when the app pool is recycling under heavy load and the memory being used as already been flushed and released, but the reference to it still exists. Is the IHTTPHandler doing anything with P/Invoke or unmanaged/unsafe code?

It is very likely it is related to the fact that ASP.NET is a multithreaded and you use non-thread safe code in the IHttpHandler.

Probably one of these:

  • COM objects (eg Excel, Word automation or similar)
  • Native Win32 API (P/Invoke)

So you need to provide more info on what exactly you do in the handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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