How to catch the special ServiceStack exceptions "response.FlushAsync()" from ServiceStack.HttpResponseExtensionsInternal?

1

The inner exception is "The remote host closed the connection. The error code is 0x80070057."

They only happen in the product environment, it's not my code, so try catch can not help.

The UncaughtExceptionHandlers also can not catch it:

 UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
                if (ex is HttpException && ex.Message.StartsWith("The remote host closed the connection", StringComparison.InvariantCultureIgnoreCase)) {
                    res.EndRequest(true); 
                }
            });

The stack trace:

   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 System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
   at System.IO.Stream.<>c.<BeginWriteInternal>b__46_0(Object )
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.IO.Stream.EndWrite(IAsyncResult asyncResult)
   at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_1(Stream stream, IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ServiceStack.StreamExtensions.<WriteToAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at ServiceStack.BufferedExtensions.<FlushBufferIfAnyAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ServiceStack.Host.AspNet.AspNetResponse.<FlushAsync>d__40.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at ServiceStack.HttpResponseExtensionsInternal.<WriteToResponse>d__7.MoveNext()
  • loggerName: ServiceStack.HttpResponseExtensionsInternal
  • ServiceStack version: 5.7.0
  • Net Framework: 4.7.2

It happens too many times, so I want to ignore it. How could do the trick with the internal async exception process?

c#
.net
servicestack
asked on Stack Overflow Aug 21, 2020 by Tom Wu

1 Answer

1

You would need to filter out the error messages from ServiceStack.HttpResponseExtensionsInternal Type in your current logger implementation.

answered on Stack Overflow Aug 21, 2020 by mythz

User contributions licensed under CC BY-SA 3.0