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.
diff --git a/src/debug.c b/src/debug.c
index b793e3e..74249ff 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -226,6 +226,7 @@
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 @@
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));