pusher / pusher-websocket-dotnet

Pusher Channels Client Library for .NET
MIT License
111 stars 113 forks source link

SemaphoreFullException #116

Closed MarkoPielic closed 2 years ago

MarkoPielic commented 2 years ago

I'm getting SemaphoreFullException when using pusher .net client in C# and it causes my application to crash. Is there any thing I can do to prevent this? The stack trace is below.

System.Threading.SemaphoreFullException: Adding the specified count to the semaphore would cause it to exceed its maximum count. at System.Threading.SemaphoreSlim.Release(Int32 releaseCount) at PusherClient.Connection.RaiseError(PusherException error) at PusherClient.Connection.WebsocketError(Object sender, ErrorEventArgs e) at WebSocket4Net.WebSocket.client_Error(Object sender, ErrorEventArgs e) at SuperSocket.ClientEngine.TcpClientSession.ProcessConnect(Socket socket, Object state, SocketAsyncEventArgs e, Exception exception) at SuperSocket.ClientEngine.ConnectAsyncExtension.SocketAsyncEventCompleted(Object sender, SocketAsyncEventArgs e) at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e) 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.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(Exception exception, Int32 bytesTransferred, SocketFlags flags) at System.Net.Sockets.MultipleConnectAsync.Fail(Boolean sync, Exception e) at System.Net.Sockets.MultipleConnectAsync.DoDnsCallback(IAsyncResult result, Boolean sync) at System.Net.Sockets.MultipleConnectAsync.DnsCallback(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) 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.Dns.ResolveCallback(Object context) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch()

benjamin-tang-pusher commented 2 years ago

Could you describe how to reproduce this error? Does it occur on the ConnectAsync() call?

MarkoPielic commented 2 years ago

@benjamin-tang-pusher Unfortunately I cannot reproduce it. But I've seen it happen couple of times in the logs I receive from my clients.

MarkoPielic commented 2 years ago

Here is one more such unreproducible error which occured only once so far:

An unhandled exception occured (AppDomain.CurrentDomain.UnhandledException): Object reference not set to an instance of an object. Object reference not set to an instance of an object. at PusherClient.Connection.DisposeWebsocket() at PusherClient.Connection.RecreateWebSocket() at PusherClient.Connection.WebsocketAutoReconnect(Object sender, EventArgs e) at WebSocket4Net.WebSocket.FireClosed() at WebSocket4Net.WebSocket.OnClosed() at SuperSocket.ClientEngine.AuthenticatedStreamTcpSession.OnDataRead(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.AsyncProtocolRequest.CompleteWithError(Exception e) at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) 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)

I think this user was having internet issues at that point because I can see a lot of messages before the exception, such as: 'WebSocket error emitted: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied' 'WebSocket error emitted: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' WebSocket error emitted: 'Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.'

Is there anything I can do to stop those errors from occurring? Like restarting the pusher connection etc.?

lisarost commented 2 years ago

@MarkoPielic is it right that this one is still open?

MarkoPielic commented 2 years ago

@lisarost Yep, still opened

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

AlexeyDunin commented 1 year ago

Have the same issue when the internet is unstable. The pusher client version is 2.2.0.0. @lisarost could you please reopen the issue?

Object reference not set to an instance of an object. Stacktrace: at PusherClient.Connection.DisposeWebsocket() at PusherClient.Connection.RecreateWebSocket() at PusherClient.Connection.WebsocketAutoReconnect(Object sender, EventArgs e) at WebSocket4Net.WebSocket.FireClosed() at WebSocket4Net.WebSocket.OnClosed() at WebSocket4Net.WebSocket.client_Error(Object sender, ErrorEventArgs e) at SuperSocket.ClientEngine.ClientSession.OnError(Exception e) at SuperSocket.ClientEngine.AuthenticatedStreamTcpSession.OnDataRead(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) 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)