HttpException: The remote host closed the connection

Hi Demis

As per our discussion here (HttpException: Server cannot set status after HTTP headers have been sent), I have a similar error that is being thrown in the global UncaughtExceptionHandlers.

System.Web.HttpException (0x800703E3): The remote host closed the connection. The error code is 0x800703E3.
   at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
   at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
   at ServiceStack.Host.AspNet.AspNetResponse.FlushAsync(CancellationToken token)
   at ServiceStack.HttpResponseExtensionsInternal.<WriteToResponse>d__7.MoveNext()

Again this has to do with streaming data (a video in this case). I think this occurs when the client closes the video midway through a stream? Nothing is actually breaking from what I can tell. Is there any way to handle this better in ServiceStack?

It throws an Exception so the Exception is raised which you can observe in your UncaughtExceptionHandlers. If you call httpRes.EndRequest() it should short-circuit further error handling.

Where should the EndRequest be called? In the UncaughtExceptionHandlers?

You can call it in UncaughtExceptionHandlers to short-circuit further processing. You may want to detect and only short-circuit HttpException as it will prevent writing other Exceptions to the Response.