I have a Blazor Server based Azure hosted web app that I'm hoping to scale out to meet peak demand.
When users login they'll have a large in memory Rete matching algorithm tree which means I can't allow them to swap between worker instances. I'm preserving the session by having ARR Affinity for the app turned on. This uses ARRAffinity and ARRAffinitySameSite cookies to ensure the load balancer sends all the requests from one session to the same worker instance.
However, I would like to have the load balancer be allowed to pick a new (less busy) worker instance every time users login. I originally tried simply deleting the affinity tokens in the login controller method:
// POST api/<controller>/login
[HttpPost("login")]
public async Task<User> Login([FromBody] User user)
{
User loginUser = new User { SiteId = user.SiteId, Username = user.Username, IsAuthenticated = false };
Response.Cookies.Delete("ARRAffinity");
Response.Cookies.Delete("ARRAffinitySameSite");
return loginUser;
}
But that didn't delete the cookies.
I then tried to set the Arr-Disable-Session-Affinity header on the logout and login pages. I did see the Header being set in the browser but the ARRAffinity survived regardless:
app.UseBlazorFrameworkFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.Use(async (context, next) =>
{
bool resetSession =
context.Request.GetUri().ToString().Contains("login")
|| context.Request.GetUri().ToString().Contains("logout");
context.Response.Headers.Add("Arr-Disable-Session-Affinity", resetSession ? "True" : "False");
if (resetSession)
{
context.Response.Cookies.Delete("ARRAffinity");
context.Response.Cookies.Delete("ARRAffinitySameSite");
}
await next();
});
Is there anyway to get the load balancer to ignore ARR Affinity during the login process?