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.
This commit is contained in:
Willy Tarreau 2022-03-31 14:49:45 +02:00
parent d8e680cbaf
commit c40c407268
1 changed files with 4 additions and 4 deletions

View File

@ -3750,16 +3750,16 @@ static int cli_parse_shutdown_session(char **args, char *payload, struct appctx
if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
return 1; 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"); return cli_err(appctx, "Session pointer expected (use 'show sess').\n");
ptr = (void *)strtoul(args[2], NULL, 0);
strm = NULL; strm = NULL;
thread_isolate(); thread_isolate();
/* first, look for the requested stream in the stream table */ /* 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) { list_for_each_entry(strm, &ha_thread_ctx[thr].streams, list) {
if (strm == ptr) { if (strm == ptr) {
stream_shutdown(strm, SF_ERR_KILLED); stream_shutdown(strm, SF_ERR_KILLED);
@ -3771,7 +3771,7 @@ static int cli_parse_shutdown_session(char **args, char *payload, struct appctx
thread_release(); thread_release();
/* do we have the stream ? */ /* do we have the stream ? */
if (!strm) if (strm != ptr)
return cli_err(appctx, "No such session (use 'show sess').\n"); return cli_err(appctx, "No such session (use 'show sess').\n");
return 1; return 1;