sta / sta/websocket-sharp

Robust and automatic client reconnection

Open
#106 0 comments 2 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

Hello,

Our application fails to reconnect the WebSocket client connection, when the TCP/IP connection is extremely bad. The problems appeared on a laptop with a terrible WiFi card but I can sometimes reproduce the problem on my laptop using culmsy, a software simulating bad networks. Comcast is similar on GNU/Linux and Mac OS X. A colleague just need to disable the WiFi for 1-2 minutes after a successful connection, the application will never reconnect.

I am not sure if it's a problem in my application, in the websocket-sharp library or even in the C# libraries. I think it's a combination of few things but I would like to have your feeling about this.

Currently, the application checks the IsAlive parameter regularly. If I read the source code correctly, this send a ping message and wait for the pong. With a bad network, the application can be blocked on this property. I suspect a dead-lock somewhere, which can be a combination of the multi-threading in my application and the multi-threading in websocket-sharp, I have no idea. Have you also experienced this problem?

Another question is how do you detect an onClose or onError event? Because isAlive can return false for minutes, then be blocked while I still haven't received an onClose event. I was considering having another "connected" property, set to true in the onOpen event, and to false in the onClose event. But I will have issues detecting a closed connection.

So another idea was a separate thread testing the isAlive parameter, and if this one is blocked or answering false I throw away the websocket and create a new one.

And finally I use the same WebSocket object after a disconnection. I wait a bit and call .Connect() again. Is it better to create a new object or it doesn't change anything?

Thank you

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

No files or tests are named. Start by reproducing the failed reconnection with culmsy or Comcast, then trace IsAlive, onOpen, onClose, onError, and Connect during a disrupted connection. Done should be defined as a verified, non-blocking reconnection behavior or a documented cause and limitation.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.