BUG/MINOR: stats: decrement srv refcount on stats-file release
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 10 Dec 2024 14:57:17 +0000 (15:57 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Jan 2025 09:18:17 +0000 (10:18 +0100)
Servers instance may be removed at runtime. This can occurs during a
stat dump which currently references this server instance. This case is
protected by server refcount to prevent the server immediate release.

CLI output may be interrupted prior to stats dump completion, for
example if client CLI has been disconnected before the full response
transfer. As such, srv_drop() must be called in every stats dump release
callback.

srv_drop() was missing for stats-file dump release callback. This could
cause a race condition which would prevent a server instance to be fully
removed. Fix this by adding srv_drop() invokation into
cli_io_handler_release_dump_stat_file().

This should be backported up to 3.0.

(cherry picked from commit 2199179461957c86f57e39c4d97c37f3e4d10935)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 41df9cac1f2092473347ee9c2f51739bf7ad0013)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/stats.c

index c3f26b0..868b925 100644 (file)
@@ -1064,6 +1064,10 @@ static int cli_io_handler_dump_stat_file(struct appctx *appctx)
 
 static void cli_io_handler_release_dump_stat_file(struct appctx *appctx)
 {
+       struct show_stat_ctx *ctx = appctx->svcctx;
+
+       if (ctx->px_st == STAT_PX_ST_SV)
+               srv_drop(ctx->obj2);
 }
 
 int stats_allocate_proxy_counters_internal(struct extra_counters **counters,