BUG/MEDIUM: cli/shutdown sessions: make it thread-safe
There's no locking around the lookup of a stream nor its shutdown
when issuing "shutdown sessions" over the CLI so the risk of crashing
the process is particularly high.
Let's use a thread_isolate() there which is suitable for this task, and
there are not that many alternatives.
This must be backported to 1.8.
(cherry picked from commit 3f5dd2945ccbed6b4baf23a453e9d1d071a2d835)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9ca4d7fb602ddc3c27e9e79c60627f4a054bf75f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit a4f1b27f5075e9bf881d1f329ad30a81e0f37650)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 0200e085c25bff07e82ba17715d8cd29a1eef3fc)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/stream.c b/src/stream.c
index 3047fe8..21c4f12 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -3737,12 +3737,18 @@
ptr = (void *)strtoul(args[2], NULL, 0);
+ thread_isolate();
+
/* first, look for the requested stream in the stream table */
list_for_each_entry(strm, &streams, list) {
- if (strm == ptr)
+ if (strm == ptr) {
+ stream_shutdown(strm, SF_ERR_KILLED);
break;
+ }
}
+ thread_release();
+
/* do we have the stream ? */
if (strm != ptr) {
appctx->ctx.cli.severity = LOG_ERR;
@@ -3751,7 +3757,6 @@
return 1;
}
- stream_shutdown(strm, SF_ERR_KILLED);
return 1;
}