doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
714 stars 123 forks source link

OnDisconnected issue on Raspberry Pi/NET 6 #372

Open ssliwa-prunus opened 2 months ago

ssliwa-prunus commented 2 months ago

Hi,

on Raspberry Pi 4 , Arch64, Linux Debian 11, .NET 6, we have a problem with getting rise OnDisconnected event. Steps to reproduce

  1. start application with disconnected network cable
  2. plug in network cable -> OnConnected event rise on about 3sec, that is OK
  3. unplug network cable -> OnDisconnected event rise after about 18 minutes, that is NOK

On Windows 10 and Windows WSL (Debian) it seems to works fine. Did you meet such a problem? Do you have any suggestions what is wrong with it?

Thanks for any help.

doghappy commented 2 months ago

The issue can be reproduced.

  1. create an ARMx64 VM on Azure.
  2. drop a ip rule from iptables

logs:

04/18/2024 14:27:02 OnPong: 00:00:00.0000438
04/18/2024 14:27:07 Ping
04/18/2024 14:27:07 OnPong: 00:00:00.0000423
04/18/2024 14:27:12 Ping
04/18/2024 14:27:12 OnPong: 00:00:00.0000620
04/18/2024 14:27:18 Ping
04/18/2024 14:27:18 OnPong: 00:00:00.0000721
04/18/2024 14:44:48 Disconnected
04/18/2024 14:45:09 OnReconnectAttempt: 1
04/18/2024 14:45:30 OnReconnectAttempt: 2
04/18/2024 14:45:51 OnReconnectAttempt: 3
04/18/2024 14:46:12 OnReconnectAttempt: 4
04/18/2024 14:46:33 OnReconnectAttempt: 5
04/18/2024 14:46:54 OnReconnectAttempt: 6
04/18/2024 14:47:15 OnReconnectAttempt: 7
04/18/2024 14:47:36 OnReconnectAttempt: 8

it takes 17 mins to get Disconnected event.

doghappy commented 2 months ago

The issue is not limited to ARM devices; it also occurs on Ubuntu x64. Because the TCP connection is not properly closed, different operating systems have different implementations, resulting in different TCP configurations.

I attempted to reproduce the issue by using the ClientWebSocket class in C# to directly connect to a WebSocket server and then dropping the connection from iptables.

Even after switching to Node.js, the disconnection may not be 'immediately' detected.

Interestingly, when I allowed access to the WebSocket server in iptables, the connection immediately resumed as if the network had not been disconnected.

babizhu commented 2 months ago

"I encountered the same issue. I directly unplugged the server's network cable, and when the client did not receive a heartbeat from the server for 90 seconds, it would actively call await _socket.DisconnectAsync(); //

However, this call takes 14 minutes to complete according to tests. Is there a way to resolve this?"