BUG/MINOR: server: adjust initialization order for dynamic servers

It appears that in cli_parse_add_server(), we're calling srv_alloc_lb()
and stats_allocate_proxy_counters_internal() before srv_preinit() which
allocates the thread groups. LB algos can make use of the per_tgrp part
which is initialized by srv_preinit(). Fortunately for now no algo uses
both tgrp and ->server_init() so this explains why this remained
unnoticed to date. Also, extra counters will soon require per_tgrp to
already be initialized. So let's move these between srv_preinit() and
srv_postinit(). It's possible that other parts will have to be moved
in between.

This could be backported to recent versions for the sake of safety but
it looks like the current code cannot tell the difference.
This commit is contained in:
Willy Tarreau 2026-02-24 20:28:50 +01:00
parent 44932b6c41
commit 709c3be845

View File

@ -6227,18 +6227,6 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
}
}
if (!srv_alloc_lb(srv, be)) {
ha_alert("Failed to initialize load-balancing data.\n");
goto out;
}
if (!stats_allocate_proxy_counters_internal(&srv->extra_counters,
COUNTERS_SV,
STATS_PX_CAP_SRV)) {
ha_alert("failed to allocate extra counters for server.\n");
goto out;
}
/* ensure minconn/maxconn consistency */
srv_minmax_conn_apply(srv);
@ -6289,6 +6277,19 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
errcode = srv_preinit(srv);
if (errcode)
goto out;
if (!srv_alloc_lb(srv, be)) {
ha_alert("Failed to initialize load-balancing data.\n");
goto out;
}
if (!stats_allocate_proxy_counters_internal(&srv->extra_counters,
COUNTERS_SV,
STATS_PX_CAP_SRV)) {
ha_alert("failed to allocate extra counters for server.\n");
goto out;
}
errcode = srv_postinit(srv);
if (errcode)
goto out;