From be68ecc37d21ec18a101e349cafe8e011e98e728 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 23 Jan 2026 10:23:27 +0100 Subject: [PATCH] BUG/MINOR: promex: Detach promex from the server on error dump its metrics dump 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index 25611c400..d3a1f6442 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -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 . It returns 1 on success, 0 if is full and -- 2.47.3