sta / sta/websocket-sharp

WebSocketSessionManager ActiveIDs getter pings every client

Open
#527 0 comments 1 reaction 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

I had a major performance issue when multiple clients are connected to my server.
I used this to send to specific clients by ID:

WebSocketServiceHost host = m_socket.WebSocketServices.Hosts.FirstOrDefault();
if (host != null)
{
    foreach (string id in host.Sessions.ActiveIDs)
    {
        if (id == myDesiredClientID)
        {
            try
            {
                host.Sessions.SendToAsync(myBase64Message, id, (bool b) => { });
            }
            catch (Exception e)
            {
                // log that something went wrong in sending
            }
        }
    }
}

After some (extensive) digging I found out that calling the getter of host.Sessions.ActiveIDs will ping every client AND wait for the answer of that ping!

Solution

I changed it to host.Sessions.IDs and it works just fine, but I don't think the getter of some list should be pinging all the clients before returning that list

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

Start by locating the WebSocketSessionManager implementations of ActiveIDs and IDs, then compare their getter behavior. Confirm the reported ping and wait when ActiveIDs is read; done means retrieving active client IDs no longer causes those client interactions while preserving the intended distinction from IDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.