question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled exception in opened handler (SocketIO v2.3.1)

See original GitHub issue

Hi @doghappy Customer sent screenshot with unhandled exception. image 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
doghappycommented, Nov 22, 2021

Seems exception occurs in OpenedHandler method at attempt to execute await Socket.SendMessageAsync(msg);

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.

0reactions
DmitryBkcommented, Nov 22, 2021

It works for me with throw new Exception(“TEST Exception”); It seems the OpenedHandler is called after the connection is established and after ConnectedHandler which set Connected = true

Sorry I was wrong, Connected is really false in that moment. My new suggestion just increments Attempts that OnReconnected event will be faired.

catch (Exception e)
{
    ErrorHandler(e.Message);

    Attempts++;
    await ConnectAsync().ConfigureAwait(false);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unhandled exceptions from socket.io or its' dependencies ...
To concisely state the expected behavior as apposed to what is actually happening: Given my application runs within a domain
Read more >
c# - When I use Socket.IO, why I got an error An unhandled ...
Open visual studio, ctrl d,e (or debug -> exceptions); Click OutOfMemoryException -> check the 'throw' box; Run the program. When the out of ......
Read more >
Troubleshooting connection issues
If that's not the case, please check that the Socket.IO server is running, and that there is nothing in between that prevents the...
Read more >
Troubleshooting connection issues
the socket is not able to connect; the socket gets disconnected; the socket is stuck in HTTP long-polling; other common gotchas. Other common ......
Read more >
Migrating from 2.x to 3.0
IO 3.1.0, the v3 server is now able to communicate with v2 clients. More information below. A v3 client is still not be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found