We recently tried incorporating Response.IsClientConnected into our asp.net site, but it causes seemingly random exceptions that only show up when we check this property. If we comment out that code, we stop getting the exceptions. We get a ton of items in our log file indicating that we have disconnected clients and we are still doing processing, so it is clearly an opportunity for optimization, but we need to figure out what is going on with the exceptions first. Any idea what is causing this exception and how we can we work around it?
Our site is hosted on Windows Server 2008 r2 x64 with IIS 7.5 and .NET 4.5.
If Not Response.IsClientConnected Then
' write to log file
End If
We are getting the following exception (again, seemingly random and only when we have the check for IsClientConnected live on our site):
System.Runtime.InteropServices.COMException (0x800703E3): The I/O operation has been aborted because of either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)
UPDATE
We are also getting a different, but related, error with much higher frequency whenever we have the check for IsClientConnected turned on. I was able to augment our error logs to get the full stack trace (see below). The error occurs before it even gets to our code. I'm guessing it is because a user is posting back the page and it is taking a long time (maybe because of an image upload) and the user cancels the request before IIS has had a chance to package up everything and hand it over to our code.
What can we do about this?
And why would the frequency with which we get these errors increase when we have the IsClientConnected check, even though that line of code never gets hit because the request never made it to our code?
Error message
System.Web.HttpException: Specified method is not supported.
Stack trace
[NotSupportedException: Specified method is not supported.]
at System.Web.HttpResponseStream.get_Position()
at System.Drawing.UnsafeNativeMethods.ComStreamFromDataStream.Seek(Int64 offset, Int32 origin)
[HttpException: An error occurred while communicating with the remote host. The error code is 0x800703E3.]
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.EnsureForm()
at System.Web.HttpRequest.get_Form()
at Aurigma.ImageUploaderFlash.UploaderModule.context_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Error message
System.Web.HttpException: The I/O operation has been aborted because of either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)
Stack trace
[COMException: The I/O operation has been aborted because of either a thread exit or an application request. (Exception from HRESULT: 0x800703E3)]
[HttpException: An error occurred while communicating with the remote host. The error code is 0x800703E3.]
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.EnsureForm()
at System.Web.HttpRequest.get_Form()
at Aurigma.ImageUploaderFlash.UploaderModule.context_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)