statianzo / Fleck

C# Websocket Implementation
MIT License
2.28k stars 583 forks source link

Memory leak when sending from the server. #326

Open wade-dp opened 2 years ago

wade-dp commented 2 years ago

We have a web socket server that is sending live data to connected clients. We are leaking large amounts of memory when I add the calls to IWebSocketConnection.Send

This could be due to how we are using the socket, but I wanted to know if there is a known issue with sending large amounts of data from the server?

public void Start(CancellationToken stoppingToken)
{
    Task.Run(async () =>
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            // read from each queue and send
            if (_binaryMessageQueue.TryDequeue(out var binaryMessage))
            {
                await Socket.Send(binaryMessage).ConfigureAwait(false);
            }
            if (_textMessageQueue.TryDequeue(out var textMessage))
            {
                await Socket.Send(textMessage).ConfigureAwait(false);
            }

            if (_binaryMessageQueue.IsEmpty && _textMessageQueue.IsEmpty)
            {
                await Task.Delay(10, stoppingToken).ConfigureAwait(false);
            }
        }
    }, stoppingToken);
}
NotoriousRebel commented 2 years ago

@wade-dp Any updates to this? Plan to use this for a project but memory leaks overtime is not ideal, PerfMon should help figure out where the memory leak is if ones exists.