BUG/MEDIUM: cli/threads: make "show threads" more robust on applets

Running several concurrent "show threads" in loops might occasionally
cause a segfault when trying to retrieve the stream from appctx_sc()
which may be null while the applet is finishing. It's not easy to
reproduce, it requires 3-5 sessions in parallel for about a minute
or so. The appctx_sc must be checked before passing it to sc_strm().

This must be backported to 2.6 which also has the bug.
This commit is contained in:
Willy Tarreau 2022-07-15 12:08:40 +02:00
parent 9b0f0d146f
commit 52f238d326

View File

@ -226,6 +226,7 @@ void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
const struct stream *s = NULL;
const struct appctx __maybe_unused *appctx = NULL;
struct hlua __maybe_unused *hlua = NULL;
const struct stconn *sc;
if (!task) {
chunk_appendf(buf, "0\n");
@ -256,8 +257,8 @@ void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx)
if (task->process == process_stream && task->context)
s = (struct stream *)task->context;
else if (task->process == task_run_applet && task->context)
s = sc_strm(appctx_sc((struct appctx *)task->context));
else if (task->process == task_run_applet && task->context && (sc = appctx_sc((struct appctx *)task->context)))
s = sc_strm(sc);
else if (task->process == sc_conn_io_cb && task->context)
s = sc_strm(((struct stconn *)task->context));