Network Disconnects - Abort or Close
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- networking
Research direction
Start by tracing NativeWebSocket's websocket.Close() to the ClientWebSocket.CloseAsync() call described in the issue. Reproduce disconnect and packet-loss behavior with Network Link Conditioner, then compare the requested Abort and CloseOutputAsync options. Done means the API choice and behavior during lost connectivity are defined and implemented with verification for the reported scenarios.
Written by the indexing model from the issue text.
Description
I came across few issues with disconnect and reconnect scenarios. I am using C# version of Websocket:
- calling
websocket.Close()hangs the client when we lose internet connection or when 100% packets drop due to poor connection (this scenario, client is connected to network, there is severe packet loss) websocket.Close()completes once network connectivity happens. But at that point, there is no reason to disconnect.- I did not check as to when timeout happens after
websocket.close()is called and network connectivity never happens. Client hangs for quite a long time on mac.
Note: I have used Network Link Conditioner on Mac to simulate network conditions apart from testing on Windows and Android. Each one of them behaves little differently. This is because OS level network settings.
ClientWebSocket has three methods CloseAsync, CloseOutputAsyncand Abort.
CloseAsyncandCloseOutputAsyncare for exchanging close frames between Server and Client. This for a more orderly shutdown when client wants to disconnect or server wants to terminate connection.Abortaborts connection and any pending I/O operations. This is asynccall and returns immediately.
Now coming back to NativeWebSocket, exposes websocket.Close() which calls CloseAsync() on ClientWebSocket. If network is disconnected, there is no point in calling CloseAsync or CloseOutputAsync as they are for terminating connections with acknowledgements. And there is no Abort method exists or a way to access ClientWebSocket as it is private.
For anyone who is curious as to how we detect network disconnects in our client - we use PingPong to send and receive msgs every n seconds/milliseconds. After sending a Ping, we don't receive a Pong within next n milliseconds - it is a disconnect.
I researched more about CloseAsync vs CloseOutputAsync and came across this article - https://mcguirev10.com/2019/08/17/how-to-close-websocket-correctly.html
Discussion points:
- Should there be a
Abortmethod onWebSocketin this library ? - Should
CloseOutputAsyncbe called instead ofCloseAsyncas client is initiating termination of websockets as per this article ?
- Dominant language
- C#
- Stars
- 1.7k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
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.
More from endel/NativeWebSocket
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
endel/NativeWebSocket#107 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
endel/NativeWebSocket#102 · 1 comment · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
endel/NativeWebSocket#101 · 6 comments · 2 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
endel/NativeWebSocket#95 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
endel/NativeWebSocket#94 · 2 comments ·
All issues in endel/NativeWebSocket
Similar issues
-
priority-0
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
StackExchange/StackExchange.Redis#3249 ·
-
[Feat] 조합 영역 구분선 개선 Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100