From c40c407268190e41d7d0238e3e2b7669147df9f7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 31 Mar 2022 14:49:45 +0200 Subject: [PATCH] BUG/MINOR: cli/stream: fix "shutdown session" to iterate over all threads The list of streams was modified in 2.4 to become per-thread with commit a698eb673 ("MINOR: streams: use one list per stream instead of a global one"). However the change applied to cli_parse_shutdown_session() is wrong, as it uses the nullity of the stream pointer to continue on next threads, but this one is not null once the list_for_each_entry() loop is finished, it points to the list's head again, so the loop doesn't check other threads, and no message is printed either to say that the stream was not found. Instead we should check if the stream is equal to the requested pointer since this is the condition to break out of the loop. Thus must be backported to 2.4. Thanks to Maciej Zdeb for reporting this. --- src/stream.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stream.c b/src/stream.c index 8acce8075..fd8dada12 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3750,16 +3750,16 @@ static int cli_parse_shutdown_session(char **args, char *payload, struct appctx if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) return 1; - if (!*args[2]) + ptr = (void *)strtoul(args[2], NULL, 0); + if (!ptr) return cli_err(appctx, "Session pointer expected (use 'show sess').\n"); - ptr = (void *)strtoul(args[2], NULL, 0); strm = NULL; thread_isolate(); /* first, look for the requested stream in the stream table */ - for (thr = 0; !strm && thr < global.nbthread; thr++) { + for (thr = 0; strm != ptr && thr < global.nbthread; thr++) { list_for_each_entry(strm, &ha_thread_ctx[thr].streams, list) { if (strm == ptr) { stream_shutdown(strm, SF_ERR_KILLED); @@ -3771,7 +3771,7 @@ static int cli_parse_shutdown_session(char **args, char *payload, struct appctx thread_release(); /* do we have the stream ? */ - if (!strm) + if (strm != ptr) return cli_err(appctx, "No such session (use 'show sess').\n"); return 1; -- 2.47.3