Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deadly exception, how to catch? System.Net.InternalException: System error

System.Net.InternalException: System error.
   at System.Net.HttpWebRequest.CheckWriteSideResponseProcessing()
   at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult retur
nResult)
   at System.Net.HttpWebRequest.WriteCallDone(ConnectStream stream, ConnectionRe
turnResult returnResult)
   at System.Net.ConnectStream.CallDone(ConnectionReturnResult returnResult)
   at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean abort
ing)
   at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeSta
te)
   at System.Net.ConnectStream.CloseInternal(Boolean internalCall)
   at System.Net.HttpWebRequest.EndWriteHeaders_Part2()
   at System.Net.HttpWebRequest.EndWriteHeaders(Boolean async)
   at System.Net.HttpWebRequest.WriteHeadersCallback(WebExceptionStatus errorSta
tus, ConnectStream stream, Boolean async)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr u
serToken)
   at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32
 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

This was caught by the unhandled exception handler. It only occurs occasionally, but with disastrous results. Any ideas how to actually catch this one chaps?

UPDATE

It has now become apparent that this only appears to happen when the CPU is under exceptionally high load.

like image 435
Tom Avatar asked May 30 '11 03:05

Tom


2 Answers

If this exception is thrown on an I/O completion thread basically without any intervention from you then I would be inclined to open a ticket with Microsoft Connect. Reasoning: You start an async I/O operation which throws an exception presumably due to a dropped connection all by it's own on the thread pool - which you can't catch. That means there is a the possibility that a dropped connection during an async operation takes down your application and you can't do anything about it. Sounds like a bug in the framework to me.

Temporary workaround could be to place a <legacyUnhandledExceptionPolicy enabled="1"/> in the <runtime> section of your app config. This will revert to the .NET 1.0/1.1 behaviour where exceptions thrown on another thread than the main thread will not take down the application. See also: http://msdn.microsoft.com/en-us/library/ms228965.aspx

like image 195
ChrisWue Avatar answered Sep 30 '22 02:09

ChrisWue


We had this same issue and were able to get assistance from Microsoft support on this. For us this was caused by a race condition in the winsock api caused by us disabling the Nagle algorithm. You might want to check out my blog post if you find yourself in the same situation: ASP.NET Serialization Exception Crash, winsock and Nagle Algorithm.

like image 21
Matt Palmerlee Avatar answered Sep 30 '22 00:09

Matt Palmerlee