Yortw / RSSDP

Really Simple Service Discovery Protocol - a 100% .Net implementation of the SSDP protocol for publishing custom/basic devices, and discovering all device types on a network.
http://yortw.github.io/RSSDP/
MIT License
282 stars 66 forks source link

[fix] handle exceptions in the thread pool #80

Closed pelengami closed 6 years ago

pelengami commented 6 years ago

Sometimes I get such exceptions and app crashes because they are raised in the thread pool. so I'd like to offer a way to handle these exceptions

Unhandled Exception  TaskScheduler.UnobservedTaskException.
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)
   at Rssdp.UdpSocket.ProcessResponse(AsyncReceiveState state, Func`1 receiveData)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.<>c__DisplayClass33_0.<<ListenToSocket>b__0>d.MoveNext()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)
   at Rssdp.UdpSocket.ProcessResponse(AsyncReceiveState state, Func`1 receiveData)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.<>c__DisplayClass33_0.<<ListenToSocket>b__0>d.MoveNext()<---
Unhandled Exception TaskScheduler.UnobservedTaskException.
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.FormatException: The format of the HTTP method is invalid.
   at System.Net.Http.HttpMethod..ctor(String method)
   at Rssdp.Infrastructure.HttpRequestParser.ParseStatusLine(String data, HttpRequestMessage message)
   at Rssdp.Infrastructure.HttpParserBase`1.Parse(T message, HttpHeaders headers, String data)
   at Rssdp.Infrastructure.HttpRequestParser.Parse(String data)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.ProcessMessage(String data, UdpEndPoint endPoint)
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.FormatException: The format of the HTTP method is invalid.
   at System.Net.Http.HttpMethod..ctor(String method)
   at Rssdp.Infrastructure.HttpRequestParser.ParseStatusLine(String data, HttpRequestMessage message)
   at Rssdp.Infrastructure.HttpParserBase`1.Parse(T message, HttpHeaders headers, String data)
   at Rssdp.Infrastructure.HttpRequestParser.Parse(String data)
   at Rssdp.Infrastructure.SsdpCommunicationsServer.ProcessMessage(String data, UdpEndPoint endPoint)
   at System.Threading.Tasks.Task.Execute()<---
Yortw commented 6 years ago

Apologies I haven't gotten to this sooner, I hope to do so next week. Thanks.