From 709c3be845d81db730c0a61268f1c1576c9e141f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 24 Feb 2026 20:28:50 +0100 Subject: [PATCH] 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. --- src/server.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/server.c b/src/server.c index 66e1513d3..10de4faa3 100644 --- a/src/server.c +++ b/src/server.c @@ -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;