From: Amaury Denoyelle Date: Wed, 9 Jun 2021 07:58:47 +0000 (+0200) Subject: BUG/MEDIUM: server: do not forget to generate the dynamic servers ids X-Git-Tag: v2.5-dev1~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=406aaef55ada9c0f31c540de404f53f74f124af8;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: server: do not forget to generate the dynamic servers ids If no id is specified by the user for a dynamic server, it is necessary to generate a new one. This operation is now done at the end of 'add server' CLI handler. The server is then inserted into the proxy ids tree. Without this, several features may be broken for dynamic servers. Among them, there is the "first" lb algorithm, the persistence using stick-tables or the uniqueness internal check of srv_parse_id. This must be backported up to 2.4. --- diff --git a/src/server.c b/src/server.c index 20121bf42f..ec4eab65d6 100644 --- a/src/server.c +++ b/src/server.c @@ -4317,7 +4317,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct struct server *srv; char *be_name, *sv_name; int errcode, argc; - int i; + int next_id, i; const int parse_flags = SRV_PARSE_DYNAMIC|SRV_PARSE_PARSE_ADDR; usermsgs_clr("CLI"); @@ -4451,6 +4451,24 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct be->srv = srv; } + /* generate the server id if not manually specified */ + if (!srv->puid) { + next_id = get_next_id(&be->conf.used_server_id, 1); + if (!next_id) { + ha_alert("Cannot attach server : no id left in proxy\n"); + goto out; + } + + srv->conf.id.key = srv->puid = next_id; + srv->conf.name.key = srv->id; + } + + /* insert the server in the backend trees */ + if (!(srv->flags & SRV_F_FORCED_ID)) { + eb32_insert(&be->conf.used_server_id, &srv->conf.id); + ebis_insert(&be->conf.used_server_name, &srv->conf.name); + } + thread_release(); ha_notice("New server registered.\n");