]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: promex: Detach promex from the server on error dump its metrics dump
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 23 Jan 2026 09:23:27 +0000 (10:23 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 23 Jan 2026 10:40:54 +0000 (11:40 +0100)
If an error occurres during the dump of a metric for a server, we must take
care to detach promex from the watcher list for this server. It must be
performed explicitly because on error, the applet state (st1) is changed, so
it is not possible to detach it during the applet release stage.

This patch must be backported with b4f64c0ab ("BUG/MEDIUM: promex: server
iteration may rely on stale server") as far as 3.0. On older versions, 2.8
and 2.6, the watcher_detach() line must be changed by "srv_drop(ctx->p[1])".

addons/promex/service-prometheus.c

index 25611c400653eb209f414206ad54be438d3268c4..d3a1f64428c0c9e9c25562056fd8ae4fbba6c8c4 100644 (file)
@@ -1255,7 +1255,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
                                labels[lb_idx].value = ist2(sv->id, strlen(sv->id));
 
                                if (!stats_fill_sv_line(px, sv, 0, stats, ST_I_PX_MAX, &(ctx->field_num)))
-                                       return -1;
+                                       goto error;
 
                                if ((ctx->flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
                                        goto next_sv;
@@ -1473,7 +1473,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
 
                                        counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod);
                                        if (!mod->fill_stats(counters, stats + ctx->field_num, &ctx->mod_field_num))
-                                               return -1;
+                                               goto error;
 
                                        val = stats[ctx->field_num + ctx->mod_field_num];
                                        metric.type = ((val.type == FN_GAUGE) ? PROMEX_MT_GAUGE : PROMEX_MT_COUNTER);
@@ -1515,6 +1515,10 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
   full:
        ret = 0;
        goto end;
+
+  error:
+       watcher_detach(&ctx->srv_watch);
+       return -1;
 }
 
 /* Dump metrics of module <mod>. It returns 1 on success, 0 if <out> is full and