Messages sent to the client by the hub are replicated for each time I have stop/started the connection.
If I execute this sequence: $.connection.hub.stop() $.connection.hub.start() {...}
and send a message from the server hub to the client, the message is received one time. If I reexecute the above sequence, I will received the same message twice, even though the server hub calls Clients.Client(Context.ConnectionId).acceptMsg(msg); only 1 time. acceptMsg is invoked twice at the client for the same message with the connectionId. I get the same results using Clients.All.acceptMsg(msg)
For each subsequent stop/start, the message is further duplicated; three messages the third time, four messages the fourth, etc.
I have tried separating invocation of the stop and start by a couple of minutes but it made no difference.
Other details: Javascript client, SignalR v2.0.1, Chrome Version 31.0.1650.63, ASP.Net 4.5. SignalR is utilizing long-polling in my test and I am allowing the default negotiation. In the SignalR trace, "SignalR: Aborted xhr request." is observed after the stop, before the start.
Any idea what is causing my messages to be replicated in this scenario?
The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command. Most of the time, such attempts will fail, but in some circumstances they might succeed.
SignalR doesn't guarantee message delivery. Since SignalR doesn't block when you call client methods, you can invoke client methods very quickly as you've discovered. Unfortunately, the client might not always be ready to receive messages immediately once you send them, so SignalR has to buffer messages.
ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available.
This is a known issue and has been fixed in the coming 2.0.2 release. Here's the GitHub issue for reference: https://github.com/SignalR/SignalR/issues/2595
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With