From: Aurelien DARRAGON Date: Mon, 30 Jun 2025 09:20:13 +0000 (+0200) Subject: BUG/MEDIUM: counters/server: fix server and proxy last_change mixup X-Git-Tag: v3.3-dev3~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d3c73c9f2c7650de356c4b75cb114a6a60282c4;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: counters/server: fix server and proxy last_change mixup 16eb0fa ("MAJOR: counters: dispatch counters over thread groups") introduced some bugs: as a result of improper copy paste during COUNTERS_SHARED_LAST() macro introduction, some functions such as srv_downtime() which used to make use of the server last_change variable now use the proxy one, which doesn't make sense and will likely cause unexpected logical errors/bugs. Let's fix them all at once by properly pointing to the server last_change variable when relevant. No backport needed. --- diff --git a/src/server.c b/src/server.c index cddfac0cf..697b9dcc5 100644 --- a/src/server.c +++ b/src/server.c @@ -144,7 +144,7 @@ const char *srv_op_st_chg_cause(enum srv_op_st_chg_cause cause) int srv_downtime(const struct server *s) { - unsigned long last_change = COUNTERS_SHARED_LAST(s->proxy->be_counters.shared->tg, last_change); + unsigned long last_change = COUNTERS_SHARED_LAST(s->counters.shared->tg, last_change); if ((s->cur_state != SRV_ST_STOPPED) || last_change >= ns_to_sec(now_ns)) // ignore negative time return s->down_time; @@ -2460,7 +2460,7 @@ INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws); */ void server_recalc_eweight(struct server *sv, int must_update) { - unsigned long last_change = COUNTERS_SHARED_LAST(sv->proxy->be_counters.shared->tg, last_change); + unsigned long last_change = COUNTERS_SHARED_LAST(sv->counters.shared->tg, last_change); struct proxy *px = sv->proxy; unsigned w; @@ -5838,7 +5838,7 @@ static int init_srv_slowstart(struct server *srv) if (srv->next_state == SRV_ST_STARTING) { task_schedule(srv->warmup, tick_add(now_ms, - MS_TO_TICKS(MAX(1000, (ns_to_sec(now_ns) - COUNTERS_SHARED_LAST(srv->proxy->be_counters.shared->tg, last_change))) / 20))); + MS_TO_TICKS(MAX(1000, (ns_to_sec(now_ns) - COUNTERS_SHARED_LAST(srv->counters.shared->tg, last_change))) / 20))); } } @@ -7035,7 +7035,7 @@ static void srv_update_status(struct server *s, int type, int cause) /* check if server stats must be updated due the the server state change */ if (srv_prev_state != s->cur_state) { if (srv_prev_state == SRV_ST_STOPPED) { - unsigned long last_change = COUNTERS_SHARED_LAST(s->proxy->be_counters.shared->tg, last_change); + unsigned long last_change = COUNTERS_SHARED_LAST(s->counters.shared->tg, last_change); /* server was down and no longer is */ if (last_change < ns_to_sec(now_ns)) // ignore negative times