-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Hi team,
Currently, calling WebSocketHub's BroadcastTextAsync concurrently throws an "invalid frame" error on client side. It seems the method is not natively thread-safe when multiple threads attempt to write at the same time.
Current Workaround:
To ensure thread safety, I had to implement a lock on the consumer side like this:
public async Task BroadcastEventAsync(string json)
{
await _writeLock.WaitAsync();
try
{
await _hub.BroadcastTextAsync("__all", json);
}
finally
{
_writeLock.Release();
}
}Proposed Solution
While the workaround functions, acquiring a lock for every broadcast isn't ideal for high-throughput scenarios.
It would be a massive improvement if the library could handle concurrency internally. Specifically, implementing an internal buffering or queuing mechanism to batch and send payloads in a performant, thread-safe manner would be fantastic. This would significantly improve developer experience and out-of-the-box performance.
Thank you for considering this enhancement!