Skip to content

[bug]example ping.c hangs when client not respond #99

Closed

Description

@habi498

Description

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.

Your environment

Describe your environment:

  • wsServer version ea8a029
  • OS version: Windows 10.
    • If Windows:

      • Is it running under MinGW? yes
  • Architecture: x86-64
  • Client: Google Chrome
    • If browser: which website?
      • Have you tested under the echo/echo.html example? yes.
ping hang

Activity

  1. added
    possible-bug
    on Sep 12, 2024
  2. Theldus commented on Sep 13, 2024

    @Theldus
    Owner

    Hi @habi498,
    Thank you for the detailed issue, this definitely looks like a bug.
    I'll take a look and keep you updated.

  3. added and removed
    possible-bug
    on Sep 16, 2024
  4. Theldus commented on Sep 16, 2024

    @Theldus
    Owner

    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() 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.

    Commit 312f112 should fix this.

    @habi498 Thank you again for reporting this.
    Please let me know if this fixes your issue.

  5. habi498 commented on Sep 17, 2024

    @habi498
    Author

    Hi @Theldus, this indeed fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions