tags:

views:

130

answers:

4

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.

A: 

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.

John Saunders
I don't do anything directly with P/Invoke or unmanaged/unsafe code. I do use MEF though, and I'm not sure if it does.
Daniel Schaffer
A: 

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

mfeingold
A: 

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?

GrayWizardx
Makes me wonder if there's a GC-related issue in there. As well as saying what the IHTTPHandler is doing, how many of them are about?
Jeremy McGee
I don't do anything directly with P/Invoke or unmanaged/unsafe code. I do use MEF though, and I'm not sure if it does.
Daniel Schaffer
Can you post relevant code from the Handler. My guess would be that you are actually popping the worker process and its recycling. Do you see high Memory usage right before this happens? Long timeouts in the handler could be causing processes to wait and using up available resources.
GrayWizardx
A: 

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 (e.g. 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.

Dmytrii Nagirniak