SignalR combined with load balancer missing messages

柔情痞子 提交于 2019-12-24 07:58:47

问题


I have 2 web servers (IIS 8.5) behind a hardware firewall and our application uses SignalR for some real-time updates. We are using SQL Server as the backplane to help us work in this load balanced environment. Additionally we are using sticky sessions on the load balancer to help us keep the users on the same web server during their session. When we are running in this hardware configuration we lose at least 1/3 of our messages. Sometimes we get all the expected messages but more often than not we are missing plenty.

When we are running on a single web server all messages are received. Does anyone have any suggestions for troubleshooting this problem? We've turned on logs (both client & server) and nothing looks like it's missing or broken. We're really stumped.

EDIT---

Some additional details that I hope will shed light on the situation.

  • Server to Client messages are getting lost. Pretty much all our communication is Server to Client.
  • We are using sticky session just based on IP and limited to 5 minutes but we're losing messages within that 5 minutes.
  • This is some old SignalR code that has been only minimally touched since SignalR 1 (or even older). We are keeping an in memory list of users along with their connections and we use that list to send notices back to the client. It seems most likely that this is the cause of the troubles but with Sticky sessions the user should be stuck to the same server for at least the 5 minutes right?
  • This list of users maps Username to connection id. This is useful when our backend services (on another machine) sends a message back with the username not the connection id.

回答1:


Finally resolved this. There were 2 issues really. The first is that we were using an in memory list of users as mentioned in the edit above. Once we realized that wasn't going to work across machines we removed it. It also led us to the second issue which was how SignalR 2 uses the IUserIdProvider and our call should have been

Clients.User(userId).send(message)

instead of

context.Clients.Client(connection)

This code had existed since we first started using SignalR many years ago and never got properly updated as we upgraded SignalR versions




回答2:


Have the same machineKey specified in your web.config on both servers.



来源:https://stackoverflow.com/questions/47007369/signalr-combined-with-load-balancer-missing-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!