How to catch this SignalR exception

2

I have an ASP.NET Web Api that uses SignalR to communicate real-time data to mobile clients. Everything is working well, but I see an exception in my trace logs and I can't seem to catch or handle this exception:

Application: 2014-05-20T03:24:57  PID[2088] Warning     SignalR exception thrown by Task: System.AggregateException: One or more errors occurred. ---> System.Web.HttpException: The remote host closed the connection. The error code is 0x800704CD.
Application:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
Application:    at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
Application:    at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
Application:    at System.Web.HttpResponse.Flush()
Application:    at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
Application:    at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.AspNet.SignalR.Owin.ServerResponse.Write(ArraySegment`1 data)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BinaryTextWriter.<.ctor>b__4(ArraySegment`1 data, Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Byte[] byteBuffer, Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.Flush()
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.PerformKeepAlive(Object state)
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.<KeepAlive>b__0(Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.TaskQueue.<Enqueue>b__1(Func`2 next, Object nextState)
Application:    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2](Func`3 func, T1 arg1, T2 arg2)
Application:    --- End of inner exception stack trace ---
Application: ---> (Inner Exception #0) System.Web.HttpException (0x800704CD): The remote host closed the connection. The error code is 0x800704CD.
Application:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
Application:    at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
Application:    at System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async)
Application:    at System.Web.HttpResponse.Flush()
Application:    at System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size)
Application:    at System.Web.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.Owin.Host.SystemWeb.CallStreams.OutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
Application:    at Microsoft.AspNet.SignalR.Owin.ServerResponse.Write(ArraySegment`1 data)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BinaryTextWriter.<.ctor>b__4(ArraySegment`1 data, Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Byte[] byteBuffer, Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.ChunkedWriter.Flush(Boolean flushEncoder)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.BufferTextWriter.Flush()
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.PerformKeepAlive(Object state)
Application:    at Microsoft.AspNet.SignalR.Transports.ServerSentEventsTransport.<KeepAlive>b__0(Object state)
Application:    at Microsoft.AspNet.SignalR.Infrastructure.TaskQueue.<Enqueue>b__1(Func`2 next, Object nextState)
Application:    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2](Func`3 func, T1 arg1, T2 arg2)<---

All of my code is wrapped in try/catch statements and I have an unobserved exception handler defined using TaskScheduler.UnobservedTaskException. If I could catch it, I could flatten the aggregate exception and process each individually.

Does anyone know how I can catch or handle this exception? It seems to happen every few minutes. Thanks in advance - I've been trying to figure this out for a while.

c#
asp.net
signalr
async-await
asked on Stack Overflow May 20, 2014 by Ender2050

1 Answer

1

You should be able to catch it with HttpApplication.Error, more details here:

Processing Unhandled Exceptions

Yet I'm surprised that none of your catch block is getting triggered. Are you sure you're wrapping every Task? You may want to try something like task.WithObservation() from here.

answered on Stack Overflow May 21, 2014 by noseratio • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0