SignalR message order?
See original GitHub issueHi.
I have a question about signalr order or messages that are received by client. Situation (server code):
...
await hubContext.Clients.All.SendAsync("EventA", "123");
await hubContext.Clients.All.SendAsync("EventB", "456");
...
Can it happen that some client will receive message 456 before message 123 (note that method name is different)?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Order of messages in SingalR - how to ensure it
1 Answer 1 ... You need to write your own mechanism. SignalR in client B has no way to know in which order...
Read more >Azure SignalR Message Delivery Queue - Microsoft Q&A
I am creating a POC using Azure SignalR in Serverless mode. ... The server can send messages thru Azure SignalR and the client...
Read more >Does SignalR Guarantee Message Deliverability?
SignalR doesn't guarantee the deliverability of messages sent from the server. ... Should they be resent in order?
Read more >Messages and connections in Azure SignalR Service
An overview of key concepts about messages and connections in Azure SignalR Service.
Read more >SignalR deep dive: Key concepts, use cases, and limitations
Going beyond ordering, SignalR doesn't guarantee message delivery - there's no message acknowledgment mechanism built-in.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is indeed unreliable. Also
Thread.Sleep
is dangerous when used in anasync
context since it blocks the entire thread which can lead to thread-pool starvation. Useawait Task.Delay(1)
when in anasync
context. Anything that “blocks” without usingawait
in anasync
context can cause significant performance problems.You are awaiting successful entry of the message in to the queue of messages to be sent out to the client. If you have no interest in awaiting that, you don’t have to.
I also want to clarify something about our ordering. We do not enforce ordering at a protocol level, thus cannot guarantee that ordering is preserved in all cases. Nor does SignalR provide any facility (built-in) to ensure ordering is preserved. However, in practice most messages will be consistently ordered across multiple clients/servers.
When you have a single server (and all clients are connected to that server), ordering should be preserved, since
SendAsync
completes when the message enters the in-memory queues for each client, and the nextSendAsync
will thus insert the message after the previous one.When multiple servers are involved, connected via a backplane such as Redis or the Azure SignalR Service, it depends on how the backplane behaves. If two servers send messages to all clients (messages
A
andB
), each server will send that message to the backplane to be distributed to all servers in the cluster. As long as the backplane preserves ordering, they should remain ordered. However, if the backplane doesn’t preserve ordering, some clients may seeA B
and other may seeB A
.The official backplanes (Redis and the Azure SignalR Service) should preserve ordering, since the underlying technologies used are ordered.
However, as I said above, since SignalR doesn’t enforce this ordering itself, we avoid making any guarantees as to ordering.
Thank you for contacting us. Due to a lack of activity on this discussion issue we’re closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn’t been addressed yet, please file a new issue.
This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!