We are using SignalR in Application. There was an exception type of:
Hub Server was unable to start. Message:One or more errors occurred. Stack trace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at ProjectName.TryStartHub(Object source, ElapsedEventArgs e)
While there was no error when we were testing at local in my system. When we deployed it with ARR. then there was an exception that was just because of ARR. While we also removed the ARR and then tried it worked. But it is not working with the ARR.
Code is correct but there is configuration issue of SignalR with ARR.
public void InitializeHub()
{
appLog.Write("Initializing Hub Server");
IHubProxy _hub;
var querystringData = new Dictionary<string, string>();
querystringData.Add("Key", "key1");
hypervisorConnection = new HubConnection("url", querystringData);
_hub = hConnection.CreateHubProxy("Hub");
_hub.On<HypervisorCommand>("ExecuteHypervisorCommand", x => ExecuteHypervisorCommand(x));
#region Initialize Hub Timer
hHubTimer = new System.Timers.Timer();
hHubTimer.Elapsed += new ElapsedEventHandler(TryStartHub);
hHubTimer.AutoReset = false;
hHubTimer.Interval = 1000;
hHubTimer.Enabled = true;
hHubTimer.Start();
#endregion
}
private void TryStartHub(object source, ElapsedEventArgs e)
{
try
{
if (hConnection.State != ConnectionState.Connected)
{
hConnection.Start().Wait();
appLog.Write("Hypervisor Hub server started.");
}
}
catch (Exception ex)
{
appLog.Write("Hub Server was unable to start. Message:" + ex.Message + "\n Stack trace:" + ex.StackTrace);
}
hHubTimer.Interval = 30000;
hHubTimer.Start();
}
So, finally we solved this issue. The issue was there in configuration of IIS load balancer ARR(Application Request Routing).
1. First, Select the ARR form IIS Menu. 2. Go to the Proxy and set the response buffer threshold to 0. Why we have to set the response buffer size to 0? Here is the detail description : By default this is set to 256kb which means that it will buffer responses until they reach that amount. By setting this to 0 ARR will no longer buffer and SignlR will function correctly.
3. And then go to the load balancer and change the load balancer algorithm from "round robin" to the "Server variable hash". Now SignalR client every time will connect to the hub.