Unhandled exception in opened handler (SocketIO v2.3.1)
See original GitHub issueHi @doghappy Customer sent screenshot with unhandled exception. and brief exception text part:
************** Exception Text ************** SocketIOClient.Exceptions.InvalidSocketStateException: Connection is not open. at SocketIOClient.WebSocketClient.ClientWebSocket.<SendMessageAsync>d__18.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SocketIOClient.WebSocketClient.ClientWebSocket.<SendMessageAsync>d__17.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SocketIOClient.SocketIO.<OpenedHandler>d__105.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Seems exception occurs in OpenedHandler
method at attempt to execute await Socket.SendMessageAsync(msg);
private async void OpenedHandler(string sid, int pingInterval, int pingTimeout)
{
Id = sid;
_pingInterval = pingInterval;
string msg = Options.EioHandler.CreateConnectionMessage(Namespace, Options.Query);
await Socket.SendMessageAsync(msg);
}
Exception was not caught in OpenedHandler()
or in OpenedProcessor.Process
, which called this method as delegate.
Can you please give recommendation how this situation is possible and how to fix code in 2.3.1 (this lib version is used in production and should be fixed).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top GitHub Comments
If the exception is indeed thrown here, it means that the WebSocket was disconnected shortly after the connection was established, causing some information of socket.io to not be sent.
If this problem occurs by accident, can it be fixed like this?
btw, I will consider adding a better solution to the latest version.
It works for me with throw new Exception(“TEST Exception”); It seems theOpenedHandler
is called after the connection is established and afterConnectedHandler
which setConnected = true
Sorry I was wrong,
Connected
is really false in that moment. My new suggestion just incrementsAttempts
thatOnReconnected
event will be faired.