You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug]example ping.c hangs when client not respond #99
I was learning about wsServer ping and pong. To test it the ping.exe in examples was run. Then a client (similar to echo.html) was connected. The client have no code to respond to ping messages. When client is connected, server says "Connected". Then after few seconds "Sending ping". If no client was connected, this message appear in every 10 seconds. But when a client is connected and after the first "Sending ping", nothing happens. I disconnected the client and cannot reconnect it. so ping program hangs i suppose.
The bug was introduced in PR #96, which added support for a client UID.
The issue is that by adding a "UID," it also necessitates looping through the list of clients to find the connection corresponding to the specific UID. This loop needs to be protected by a mutex to prevent modifications to the client list while it's being traversed, and this part works perfectly fine.
The fix is quite simple: switch from using ws_sendframe() to ws_sendframe_internal(), since the latter does not rely on the client's UID but instead uses the connection structure, which was already obtained earlier. This way, no additional locks are needed, and the code runs without issues.
Activity
Theldus commentedon Sep 13, 2024
Hi @habi498,
Thank you for the detailed issue, this definitely looks like a bug.
I'll take a look and keep you updated.
Theldus commentedon Sep 16, 2024
The bug was introduced in PR #96, which added support for a client UID.
The issue is that by adding a "UID," it also necessitates looping through the list of clients to find the connection corresponding to the specific UID. This loop needs to be protected by a mutex to prevent modifications to the client list while it's being traversed, and this part works perfectly fine.
The problem occurs when a ping broadcast is sent to all active clients. In that case, the client list is also locked with the same mutex, causing the code to enter a blocking state.
The fix is quite simple: switch from using
ws_sendframe()tows_sendframe_internal(), since the latter does not rely on the client's UID but instead uses the connection structure, which was already obtained earlier. This way, no additional locks are needed, and the code runs without issues.Commit 312f112 should fix this.
@habi498 Thank you again for reporting this.
Please let me know if this fixes your issue.
habi498 commentedon Sep 17, 2024
Hi @Theldus, this indeed fixes the issue.