Commit 0732d589 authored by Vincent Pelletier's avatar Vincent Pelletier

ERP5Type.patches.CookieCrumbler: Fix balancer cookie logic.

Ever since the introduction of X-Balancer-Current-Server in SlapOS
haproxy configuration in:
  commit c7f104fbf1f5948928f5545286afbb94fc39102b
  Author: Cédric Le Ninivin <cedric.leninivin@tiolive.com>
  Date:   Tue May 26 13:27:33 2015 +0200

      erp5_cluster: leave ERP5 set the haproxy cookie

the balancer will overwrite this cookie's value, so do not compare it
to our name: balancer may be calling us a name completely unrelated to
the value getCurrentNode returns.
So simplify this function's logic to only do what the docstring says:
decide when to set and when to unset the balancer cookie, and let the
balancer decide the value.
This resolves cases where Zope would set the cookie over and over on
every request when getCurrentNode and balancer disagree on its value.
parent d9aa24ad
......@@ -86,6 +86,7 @@ def balancer_cookie_hook(ob, req, resp):
complicate code with automatic upgrade, this one is implemented by
pluging into CookieCrumbler, although what they are quite unrelated.
"""
# Balancer gives us the name of the cookie it wants to use.
balancer_cookie = req.get('HTTP_X_BALANCER_CURRENT_COOKIE')
if balancer_cookie:
try:
......@@ -96,11 +97,10 @@ def balancer_cookie_hook(ob, req, resp):
if balancer_cookie in req.cookies:
resp.expireCookie(balancer_cookie, path=path)
else:
from product.CMFActivity.ActivityTool import getCurrentNode
server_id = getCurrentNode()
# The format of server_id must be exactly the same for any balancer in front
if server_id != req.cookies.get(balancer_cookie):
resp.setCookie(balancer_cookie, server_id, path=path);
if balancer_cookie not in req.cookies:
# Balancer is expected to rewrite this cookie's value to whatever
# our identifier (from its point of view) is.
resp.setCookie(balancer_cookie, 'anything', path=path);
def modifyRequest(self, req, resp):
"""Copies cookie-supplied credentials to the basic auth fields.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment