Code-Sharp / WampSharp

A C# implementation of WAMP (The Web Application Messaging Protocol)
http://wampsharp.net
Other
385 stars 84 forks source link

Unhandled terminating exception due to async void #360

Closed manveldavid closed 10 months ago

manveldavid commented 11 months ago

WampSharp.WebSocket.WebSocketWrapperConnection<TMessage, TRaw>.InnerConnection() is async void:

  protected async **void** InnerConnect()
  {
      bool connected = await TryConnect();

      if (connected)
      {
          await Task.Run(this.RunAsync, mCancellationToken).ConfigureAwait(false);
      }
  }

This error causes the conclusion to be unable to be caught and to break the execution of the program. Replace an async void to async Task.

Unhandled Exception: System.Net.WebSockets.WebSocketException: 'The remote party closed the WebSocket connection without completing the close handshake.' This exception is terminated and it permanent broke runtime.

StackTrace: System.Net.WebSockets.WebSocketException HResult=0x80004005 Message=The remote party closed the WebSocket connection without completing the close handshake. Source=System.Net.WebSockets StackTrace: at System.Net.WebSockets.ManagedWebSocket.d631.MoveNext() in /_/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/ManagedWebSocket.cs:line 872 at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs:line 428 at System.Threading.Tasks.ValueTask1.ValueTaskSourceAsTask.<>c.<.cctor>b40(Object state) in //src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs:line 669 --- End of stack trace from previous location --- at WampSharp.WebSockets.WebSocketWrapperConnection2.<ReadMessage>d__18.MoveNext() in C:\workspace\WampSharp\src\netstandard\Extensions\WampSharp.WebSockets\WebSockets\WebSocketWrapperConnection.cs:line 207 at WampSharp.WebSockets.WebSocketWrapperConnection2.d16.MoveNext() in C:\workspace\WampSharp\src\netstandard\Extensions\WampSharp.WebSockets\WebSockets\WebSocketWrapperConnection.cs:line 147 at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\ExceptionServicesImpl.cs:line 16 at System.Reactive.ExceptionHelpers.Throw(Exception exception) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\ExceptionServices.cs:line 14 at System.Reactive.Stubs.<>c.<.cctor>b21(Exception ex) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Stubs.cs:line 16 at System.Reactive.AnonymousSafeObserver1.OnError(Exception error) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\AnonymousSafeObserver.cs:line 62 at System.Reactive.Sink1.ForwardOnError(Exception error) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Sink.cs:line 61 at System.Reactive.Linq.ObservableImpl.Merge`1.Observables..InnerObserver.OnError(Exception error) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\Merge.cs:line 244 at System.Reactive.Sink1.ForwardOnError(Exception error) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Sink.cs:line 61 at System.Reactive.Linq.ObservableImpl.SelectMany2.ObservableSelector._.InnerObserver.OnError(Exception error) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\SelectMany.cs:line 954 at System.Reactive.Linq.ObservableImpl.ThrowImmediate1.Run(IObserver1 observer) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\Throw.cs:line 57 at System.Reactive.BasicProducer1.<>c.<SubscribeRaw>b__1_0(ValueTuple3 tuple) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Producer.cs:line 60 at System.Reactive.Concurrency.Scheduler.<>c76`1.b760(IScheduler , ValueTuple2 tuple) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Concurrency\Scheduler.Simple.cs:line 88 at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[TState](TState state, TimeSpan dueTime, Func3 action) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Concurrency\CurrentThreadScheduler.cs:line 101 at System.Reactive.Concurrency.LocalScheduler.Schedule[TState](TState state, Func3 action) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Concurrency\LocalScheduler.cs:line 32 at System.Reactive.Concurrency.Scheduler.ScheduleAction[TState](IScheduler scheduler, TState state, Func2 action) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Concurrency\Scheduler.Simple.cs:line 86 at System.Reactive.BasicProducer1.SubscribeRaw(IObserver1 observer, Boolean enableSafeguard) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Internal\Producer.cs:line 62 at System.Reactive.Linq.ObservableImpl.SelectMany2.ObservableSelector._.SubscribeInner(IObservable1 inner) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\SelectMany.cs:line 930 at System.Reactive.Linq.ObservableImpl.SelectMany2.ObservableSelector._.OnNext(TSource value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\SelectMany.cs:line 877 at System.Reactive.Subjects.Subject1.OnNext(T value) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Subjects\Subject.cs:line 148 at System.Reactive.Linq.ObservableImpl.FromEventPattern.Impl2.<>c__DisplayClass3_0.<GetHandler>b__0(Object sender, TEventArgs eventArgs) in D:\a\1\s\Rx.NET\Source\src\System.Reactive\Linq\Observable\FromEventPattern.cs:line 44 at WampSharp.V2.Client.WampSessionClient1.OnConnectionError(WampConnectionErrorEventArgs e) in C:\workspace\WampSharp\src\netstandard\WampSharp\WAMP2\V2\Client\Session\WampSessionClient.cs:line 248 at WampSharp.V2.Client.WampSessionClient1.OnConnectionError(Exception exception) in C:\workspace\WampSharp\src\netstandard\WampSharp\WAMP2\V2\Client\Session\WampSessionClient.cs:line 219 at WampSharp.V2.Client.WampClient1.OnConnectionError(Exception exception) in C:\workspace\WampSharp\src\netstandard\WampSharp\WAMP2\V2\Client\WampClient.cs:line 99 at WampSharp.V2.Client.WampChannel1.OnConnectionError(Object sender, WampConnectionErrorEventArgs e) in C:\workspace\WampSharp\src\netstandard\WampSharp\WAMP2\V2\Client\WampChannel.cs:line 40 at WampSharp.Core.Listener.ReviveClientConnection1.RaiseConnectionError(WampConnectionErrorEventArgs e) in C:\workspace\WampSharp\src\netstandard\WampSharp\Core\Listener\Connections\ReviveClientConnection.cs:line 116 at WampSharp.Core.Listener.ReviveClientConnection1.OnConnectionError(Object sender, WampConnectionErrorEventArgs e) in C:\workspace\WampSharp\src\netstandard\WampSharp\Core\Listener\Connections\ReviveClientConnection.cs:line 45 at WampSharp.Core.Listener.AsyncWampConnection1.RaiseConnectionError(Exception ex) in C:\workspace\WampSharp\src\netstandard\WampSharp\Core\Listener\Connections\AsyncConnection\AsyncWampConnection.cs:line 82 at WampSharp.WebSockets.WebSocketWrapperConnection2.<RunAsync>d__16.MoveNext() in C:\workspace\WampSharp\src\netstandard\Extensions\WampSharp.WebSockets\WebSockets\WebSocketWrapperConnection.cs:line 167 at WampSharp.WebSockets.WebSocketWrapperConnection2.d12.MoveNext() in C:\workspace\WampSharp\src\netstandard\Extensions\WampSharp.WebSockets\WebSockets\WebSocketWrapperConnection.cs:line 101 at System.Threading.Tasks.Task.<>c.b1281(Object state) in //src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 1929 at System.Threading.ThreadPoolWorkQueue.Dispatch() in //src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 867 at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in //src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:line 77

Inner Exception 1: IOException: Unable to read data from the transport connection: The remote host forcibly closed the existing connection.

Inner Exception 2: SocketException: The remote host forcibly closed the existing connection.

darkl commented 11 months ago

Will replacing the void with a Task suffice? No one is awaiting this Task.

manveldavid commented 11 months ago

Ok, but this is important for throwing and catching exceptions.

manveldavid commented 11 months ago

I clone your library, changed void to task and exceptions started working correctly, they can now be caught and handled

darkl commented 11 months ago

Okay, I will fix this.

manveldavid commented 11 months ago

Thank You so much!

manveldavid commented 11 months ago

What's the time frame to expect a fix?