Skip to content

Unhandeled exception #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
seba76 opened this issue May 29, 2017 · 9 comments
Closed

Unhandeled exception #193

seba76 opened this issue May 29, 2017 · 9 comments

Comments

@seba76
Copy link

seba76 commented May 29, 2017

Closing tcp connection forcibly can lead to unhandled exception. To reproduce problem connect to any server as subscriber. Then in some tool as TCPView close conection to server you subscribed to. This will throw exception like:
An unhandled exception occurred WampSharp.V2.Core.Contracts.WampConnectionBrokenException: Connection got broken. CloseType:Disconnection
at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
at System.Reactive.Stubs.<>c.<.cctor>b__2_1(Exception ex)
at System.Reactive.AnonymousSafeObserver1.OnError(Exception error) at System.Reactive.Linq.ObservableImpl.Merge1..Iter.OnError(Exception error)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.Iter.OnError(Exception error) at System.Reactive.Linq.ObservableImpl.Throw1.
.Invoke()
at System.Reactive.Concurrency.Scheduler.Invoke(IScheduler scheduler, Action action)
at System.Reactive.Concurrency.ImmediateScheduler.Schedule[TState](TState state, Func3 action) at System.Reactive.Concurrency.Scheduler.Schedule(IScheduler scheduler, Action action) at System.Reactive.Linq.ObservableImpl.Throw1._.Run()
at System.Reactive.Linq.ObservableImpl.Throw1.Run(IObserver1 observer, IDisposable cancel, Action1 setSink) at System.Reactive.Producer1.Run(IScheduler _, State x)
at System.Reactive.Concurrency.ScheduledItem2.InvokeCore() at System.Reactive.Concurrency.CurrentThreadScheduler.Trampoline.Run(SchedulerQueue1 queue)
at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[TState](TState state, TimeSpan dueTime, Func3 action) at System.Reactive.Concurrency.LocalScheduler.Schedule[TState](TState state, Func3 action)
at System.Reactive.Producer1.SubscribeRaw(IObserver1 observer, Boolean enableSafeguard)
at System.ObservableExtensions.SubscribeSafe[T](IObservable1 source, IObserver1 observer)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.SubscribeInner(IObservable1 inner)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.OnNext(TSource value) at System.Reactive.Subjects.Subject1.OnNext(T value)
at System.Reactive.Linq.ObservableImpl.FromEventPattern.Impl2.<>c__DisplayClass3_0.<GetHandler>b__1(Object sender, TEventArgs eventArgs) at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at WampSharp.V2.Client.WampSessionClient1.OnConnectionBroken(WampSessionCloseEventArgs e) at WampSharp.V2.Client.WampSessionClient1.RaiseConnectionBroken()
at WampSharp.V2.Client.WampSessionClient1.OnConnectionClosed() at WampSharp.V2.Client.WampChannel1.OnConnectionClosed(Object sender, EventArgs e)
at WampSharp.Core.Listener.ReviveClientConnection1.RaiseConnectionClosed() at WampSharp.Core.Listener.ReviveClientConnection1.OnConnectionClosed(Object sender, EventArgs e)
at WampSharp.WebSocket4Net.WebSocket4NetConnection1.RaiseConnectionClosed() at WampSharp.WebSocket4Net.WebSocket4NetConnection1.WebSocketOnClosed(Object sender, EventArgs eventArgs)
at WebSocket4Net.WebSocket.FireClosed()
at WebSocket4Net.WebSocket.OnClosed()
at WebSocket4Net.WebSocket.client_Closed(Object sender, EventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnClosed()
at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security.SslStream.StartFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.ReadHeaderCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) stack trace at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
at System.Reactive.Stubs.<>c.<.cctor>b__2_1(Exception ex)
at System.Reactive.AnonymousSafeObserver1.OnError(Exception error) at System.Reactive.Linq.ObservableImpl.Merge1.
.Iter.OnError(Exception error)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.Iter.OnError(Exception error) at System.Reactive.Linq.ObservableImpl.Throw1.
.Invoke()
at System.Reactive.Concurrency.Scheduler.Invoke(IScheduler scheduler, Action action)
at System.Reactive.Concurrency.ImmediateScheduler.Schedule[TState](TState state, Func3 action) at System.Reactive.Concurrency.Scheduler.Schedule(IScheduler scheduler, Action action) at System.Reactive.Linq.ObservableImpl.Throw1.
.Run()
at System.Reactive.Linq.ObservableImpl.Throw1.Run(IObserver1 observer, IDisposable cancel, Action1 setSink) at System.Reactive.Producer1.Run(IScheduler _, State x)
at System.Reactive.Concurrency.ScheduledItem2.InvokeCore() at System.Reactive.Concurrency.CurrentThreadScheduler.Trampoline.Run(SchedulerQueue1 queue)
at System.Reactive.Concurrency.CurrentThreadScheduler.Schedule[TState](TState state, TimeSpan dueTime, Func3 action) at System.Reactive.Concurrency.LocalScheduler.Schedule[TState](TState state, Func3 action)
at System.Reactive.Producer1.SubscribeRaw(IObserver1 observer, Boolean enableSafeguard)
at System.ObservableExtensions.SubscribeSafe[T](IObservable1 source, IObserver1 observer)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.SubscribeInner(IObservable1 inner)
at System.Reactive.Linq.ObservableImpl.SelectMany2._.OnNext(TSource value) at System.Reactive.Subjects.Subject1.OnNext(T value)
at System.Reactive.Linq.ObservableImpl.FromEventPattern.Impl2.<>c__DisplayClass3_0.<GetHandler>b__1(Object sender, TEventArgs eventArgs) at System.EventHandler1.Invoke(Object sender, TEventArgs e)
at WampSharp.V2.Client.WampSessionClient1.OnConnectionBroken(WampSessionCloseEventArgs e) at WampSharp.V2.Client.WampSessionClient1.RaiseConnectionBroken()
at WampSharp.V2.Client.WampSessionClient1.OnConnectionClosed() at WampSharp.V2.Client.WampChannel1.OnConnectionClosed(Object sender, EventArgs e)
at WampSharp.Core.Listener.ReviveClientConnection1.RaiseConnectionClosed() at WampSharp.Core.Listener.ReviveClientConnection1.OnConnectionClosed(Object sender, EventArgs e)
at WampSharp.WebSocket4Net.WebSocket4NetConnection1.RaiseConnectionClosed() at WampSharp.WebSocket4Net.WebSocket4NetConnection1.WebSocketOnClosed(Object sender, EventArgs eventArgs)
at WebSocket4Net.WebSocket.FireClosed()
at WebSocket4Net.WebSocket.OnClosed()
at WebSocket4Net.WebSocket.client_Closed(Object sender, EventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnClosed()
at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security._SslStream.StartFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ReadHeaderCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) Connection got broken. CloseType:Disconnection

@darkl
Copy link
Member

darkl commented May 29, 2017

In order to prevent this exception, please provide an OnError handler to the IObservable Subscribe extension method.

@seba76
Copy link
Author

seba76 commented May 29, 2017

Thanks, I missed that overload. Might me good idea to add it as an example in documentation pages.

@seba76 seba76 closed this as completed May 29, 2017
@seba76 seba76 reopened this May 29, 2017
@darkl darkl closed this as completed May 29, 2017
@seba76
Copy link
Author

seba76 commented May 29, 2017

I had an old dll when i closed issue, with original from nuget I still get an error. Can you give mi a hint what am I missing here:
var factory = new DefaultWampChannelFactory();
var channel = factory.CreateJsonChannel(Settings.Url, "realm1");
var realmProxy = channel.RealmProxy;
Func conTask = async () =>
{
await channel.Open();
var subject = realmProxy.Services.GetSubject(ins);
var subscription = subject.Subscribe(y => HandleMessage(y), er => LogEx(er));
}
WampChannelReconnector reconnector = new WampChannelReconnector(channel, () =>
{
conTask();
return null;
});

reconnector.Start();

@darkl
Copy link
Member

darkl commented May 29, 2017 via email

@seba76
Copy link
Author

seba76 commented May 29, 2017

Hi,
Thaks for taking time to check this issue I'm having. I changed reconnector line to
WampChannelReconnector reconnector = new WampChannelReconnector(channel, () =>
{
return conTask();
});

but this doesn't help also. Only fix that works for me is wrapping callback call in OnConnectionError method of WampSessionClient.

@darkl
Copy link
Member

darkl commented May 29, 2017 via email

@seba76
Copy link
Author

seba76 commented May 30, 2017

Hi, here is the project that can lead to unhandled exception. All code is in program.cs. You would also need TCPView tool free download form https://technet.microsoft.com/en-us/sysinternals/tcpview.aspx. Steps to reproduce problem:

  1. Start sample in debugger
  2. Start TCPView and located debuged exe (it should be wampclient.vshost.exe) in window
  3. In TCPView right click on exe and select close connection
  4. Debugger will report unhandled exception and continuing will crash application

WampClient.zip

@darkl
Copy link
Member

darkl commented May 30, 2017 via email

@seba76
Copy link
Author

seba76 commented May 31, 2017

You are right! Thank you for your help. First time I tired your suggestion I commented out first subscription and forgot to add OnError to it. That is the reason I closed issue at first and then reopened it.

One again thanks for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants