Question

The situation is a single javascript client on a SignalR (v1.1.2 from NuGet) persistent connection in an ASP.NET MVC4 project. Once connected I send multiple messages in a row from the client to the server. On the server my OnReceived override function gets called from multiple threads at the same time which causes the messages to be received out of order since it becomes a race to see which one hits my lock first. Messages sent from the server to the client appear to be delivered in order though that could just be luck.

Is there any expectation of message order in either direction for an individual client? Is there any documentation that I'm missing that lists the guarantees made by the persistent connection?

Do I need to do anything special to ensure server to client messages are kept in order as well? A majority of my sends come asynchronously from outside of the persistent connection so I'm currently just calling IConnection.Send and ignoring the returned Task.

Was it helpful?

Solution

The quick answer is no. When you send messages from server to client, things will always be in order. Sending from client to server however, the only transport that queues outgoing client to server calls is websockets.

With persistent connections you're out of luck when trying to order sends from client to server as there's no way to know when the send is complete. Hubs on the other hand return a deferred (and task in C#), which lets you wait on the send to complete before sending again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top