sta / sta/websocket-sharp

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

Open
#735 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
6.1k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

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.)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WebSocket.close:0 error and trace the flow through the shown Connect, WebSocketClose, Reconnect, and sentRegisterRequest entry points. Reproduce a disconnect during the retry sequence and determine where the canceled task is surfaced. Done means the source of the close failure and the expected handling are identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.