-
Notifications
You must be signed in to change notification settings - Fork 124
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
Unhandled exception in opened handler (SocketIO v2.3.1) #239
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? private async void OpenedHandler(string sid, int pingInterval, int pingTimeout)
{
Id = sid;
_pingInterval = pingInterval;
string msg = Options.EioHandler.CreateConnectionMessage(Namespace, Options.Query);
try
{
throw new Exception("TEST Exception");
// await Socket.SendMessageAsync(msg).ConfigureAwait(false);
}
catch (Exception e)
{
ErrorHandler(e.Message);
await ConnectAsync().ConfigureAwait(false);
}
} btw, I will consider adding a better solution to the latest version. |
@doghappy |
I suggest you based on this branch https://github.com/doghappy/socket.io-client-csharp/tree/v2.x |
Do you mean to make a PR in v2.x branch with this fix? |
no.
I suggest you base on this branch https://github.com/doghappy/socket.io-client-csharp/tree/v2.x instead of downloading from the release page. It is better if you are willing to submit a PR :) btw, I would rather find the real reason, maybe it is the network reason, or something else? Do you have any suggestions? In v3.x, I added a retry mechanism, I don't know which way is better. |
Of course, it is a rare case but I would suggest starting standard reconnection flow for this case private async void OpenedHandler(string sid, int pingInterval, int pingTimeout)
{
try
{
Id = sid;
_pingInterval = pingInterval;
string msg = Options.EioHandler.CreateConnectionMessage(Namespace, Options.Query);
await Socket.SendMessageAsync(msg).ConfigureAwait(false);
}
catch (Exception e)
{
ErrorHandler(e.Message);
Attempts++;
await InvokeDisconnectAsync(e.Message).ConfigureAwait(false);
}
} |
There is an if condition in InvokeDisconnectAsync socket.io-client-csharp/src/SocketIOClient/SocketIO.cs Lines 635 to 655 in d523efe
When an exception is thrown in OpenedHandler, the value of At this point, WS has been established, but socket.io has not been established yet. The data sent by OpenedHandler is to establish socket.io connection on the basis of WS. |
Sorry I was wrong,
|
Hi @doghappy
![image](https://user-images.githubusercontent.com/11534020/142597587-c259b3c8-7327-4616-8a03-e08033cb08e8.png)
Customer sent screenshot with unhandled exception.
and brief exception text part:
Seems exception occurs in
OpenedHandler
method at attempt to executeawait Socket.SendMessageAsync(msg);
Exception was not caught in
OpenedHandler()
or inOpenedProcessor.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).
The text was updated successfully, but these errors were encountered: