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.
This commit is contained in:
Aurelien DARRAGON 2025-06-30 11:20:13 +02:00
parent 837762e2ee
commit 9d3c73c9f2

View File

@ -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