question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SignalR message order?

See original GitHub issue

Hi.

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
analogrelaycommented, Apr 18, 2019

Why would Thread.Sleep change anything? Feels unreliable.

That is indeed unreliable. Also Thread.Sleep is dangerous when used in an async context since it blocks the entire thread which can lead to thread-pool starvation. Use await Task.Delay(1) when in an async context. Anything that “blocks” without using await in an async context can cause significant performance problems.

If ordering is not guaranteed what the purpose of SendAsync api that allows you to await something?

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 next SendAsync 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 and B), 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 see A B and other may see B 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.

0reactions
msftbot[bot]commented, Nov 12, 2020

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found