From: Damien Claisse Date: Wed, 27 Mar 2024 14:34:25 +0000 (+0000) Subject: BUG/MINOR: server: fix persistence cookie for dynamic servers X-Git-Tag: v3.0-dev7~67 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a0e0d3a19312d00e4dc20e3257e5238961409e7;p=thirdparty%2Fhaproxy.git BUG/MINOR: server: fix persistence cookie for dynamic servers When adding a server dynamically, we observe that when a backend has a dynamic persistence cookie, the new server has no cookie as we receive the following HTTP header: set-cookie: test-cookie=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/ Whereas we were expecting to receive something like the following, which is what we receive for a server added in the config file: set-cookie: test-cookie=abcdef1234567890; path=/ After investigating code path, srv_set_dyncookie() is never called when adding a server through CLI, it is only called when parsing config file or using "set server bkd1/srv1 addr". To fix this, call srv_set_dyncookie() inside cli_parse_add_server(). This patch must be backported up to 2.4. --- diff --git a/src/server.c b/src/server.c index 2f780b2b78..008335bfe0 100644 --- a/src/server.c +++ b/src/server.c @@ -5732,6 +5732,11 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct */ srv->rid = (srv_id_reuse_cnt) ? (srv_id_reuse_cnt / 2) : 0; + /* generate new server's dynamic cookie if enabled on backend */ + if (be->ck_opts & PR_CK_DYNAMIC) { + srv_set_dyncookie(srv); + } + /* adding server cannot fail when we reach this: * publishing EVENT_HDL_SUB_SERVER_ADD */