Skip to content
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

When websocket closed with error "One or more errors occurred. (A task was canceled.)" #735

Open
renjuashokan opened this issue Aug 30, 2023 · 0 comments

Comments

@renjuashokan
Copy link

I am having an http server, that server returns a websocket address on a specific http request.
Then my project connects to that websocket server.

When websocket disconnection happens, my project sends the HTTP request again gets the new websocket url.
This retry logic was done like below.

private void Connect()
{
   webSocket = new WebSocket(m_websocketUrl);

   webSocket.EmitOnPing = true;
   webSocket.OnOpen += WebSocketOpened;
   webSocket.OnClose += WebSocketClose;
   webSocket.OnMessage += WebSocketMessageReceived;
   webSocket.OnError += WebSocketError;
   webSocket.WaitTime = TimeSpan.FromSeconds(20);
   webSocket.OnClose += WebSocketClose;
}

private void WebSocketClose(object obj, WebSocketSharp.CloseEventArgs e)
{
      Console.WriteLine("websocket closed");
 
      Reconnect();
}

private void Reconnect()
{
        System.Threading.Thread.Sleep(1000 * 60);
        Console.WriteLine("Re Registering with Saved Request");
        m_remoteClient.sentRegisterRequest(); // this function gets a new websocket url.
 }

But sometimes I can see websocket close failed with the following error and not able to track from where this is coming

08/23/2023 1:23:26|Error|WebSocket.close:0|One or more errors occurred. (A task was canceled.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant