From 5f164530825111219ae79b87df047808e36f4830 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Wed, 9 Oct 2024 19:23:41 +0200 Subject: [PATCH] MEDIUM: mworker: block reloads When reloads arrive very often (sent by some APIs), newly forked workers almost don't have a time to load completely and to send its READY status to master, which allows then to stop the previous worker (launched before reload). As a result, the number of workers increases very quickly, previous workers are still alive and the memory consumption is very high. To avoid such situations let's return in cli_parse_reload() reload status 0 with the text ""Another reload is still in progress", if there is still a process with PROC_O_INIT flag in the processes list. --- src/mworker.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mworker.c b/src/mworker.c index 431935852c..7d3c831c97 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -699,10 +699,27 @@ static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, v struct connection *conn = NULL; int fd = -1; int hardreload = 0; + struct mworker_proc *proc; if (!cli_has_level(appctx, ACCESS_LVL_OPER)) return 1; + list_for_each_entry(proc, &proc_list, list) { + /* if there is a process with PROC_O_INIT, i.e. new worker is + * doing its init routine, block the reload + */ + if (proc->options & PROC_O_INIT) { + chunk_printf(&trash, "Success=0\n"); + chunk_appendf(&trash, "--\n"); + chunk_appendf(&trash, "Another reload is still in progress.\n"); + + if (applet_putchk(appctx, &trash) == -1) + return 0; + + return 1; + } + } + /* hard reload requested */ if (*args[0] == 'h') hardreload = 1; -- 2.47.3