Azure / azure-signalr

Azure SignalR Service SDK for .NET
https://aka.ms/signalr-service
MIT License
427 stars 101 forks source link

Can one azure signalr service instance be used by multiple web server (Sharepoint Server 2016) with same hostname #1680

Open RileyZHOU opened 2 years ago

RileyZHOU commented 2 years ago

Hi, Genius,

I wanted to know is if Azure SignalR (Default mode) can work with two web servers in a HA mode with following conditions:

Two web servers are running independent of one another with different IPs on Azure, but their hostname are the same. e.g web server A ( xxx.abc.com, IP 10.10.1.1) & web server B ( xxx.abc.com, IP,10.10.1.2 ) configured on the AD DNS. There is an Azure application gateway with cookie-affinity enabled and point those two backend web servers.

The problem I am facing now is that the Azure SignalR is able to work when user login to the web server at first place, let's say the connection is pointing to web server A on 10.10.1.1, but few time after the page refreshed, the connection was dropped, and our dev team is found the connection web server connection is swapped from web server A to B on 10.10.1.2, which we think this might be the cause.

So is there a way we can keep the Azure signalR to send all the following request towards the same server, or we literally have setup two different hostname on two web server in order to make the Azure signalR distinguish the backend web server it connects to ?

Hope this make sense. Thanks !

vicancy commented 2 years ago

Since it is the web server that initiates server connection requests to Azure SignalR, I don't think web server hostname matters to Azure SignalR. What matters to Azure SignalR is that if different web apps connect to Azure SignalR using the same Hub name, Azure SignalR considers these apps are different instances of the same application so it by default randomly picks one server connection to route the client connections to.

I want to understand more about your HA mode, and if it is HA mode, why clients routed to server B can fail the client? Is there any state info when client "negotaite" with your server? How many running instances for one web server? If each web server has one running instance and you want to sticky the client to the instance that doing the "negotiation" you can try this "ServerSticky" option: https://github.com/Azure/azure-signalr/blob/dev/docs/run-asp-net-core.md#serverstickymode

RileyZHOU commented 2 years ago

Hi Vicancy,

Thanks for your response. Your assumption is correct, the different web app connect to Azure signalR with the same hub name. Regarding the HA mode, we have two web server (two Azure VMs with SharePoint Server 2016 installed) as a front end, which being placed behind the Azure application gateway with cookie-affinity enabled.

I wonder if there is a technical limitation for two web server connected to one Azure signalR with same hub name ? Or the "ServerSticky" mode would fit the above scenario with same hub name.

PS: I would try get some updates from our dev team as well.

vicancy commented 2 years ago

Are these two web server considered as two different hub applications that have different hub logics in each? If they are actually different hub logic, you can set different ApplicationName to isolate these two web servers: https://github.com/Azure/azure-signalr/blob/dev/docs/run-asp-net-core.md#applicationname

If they are the same hub but just different running instances but you have a special state kept during the "negotiate" state, while you'd like connections connected to different instances talking to each other (for example broadcast from one hub server can be received by clients connected to both servers), you can use "ServerSticky".