When websocket closed with error "One or more errors occurred. (A task was canceled.)"
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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