From 90034bba15022b85a875aae3c9a4cde9a4724400 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 10 Nov 2021 11:26:14 +0100 Subject: [PATCH] MINOR: mworker: change the way we set PROC_O_LEAVING Since the wait mode is always used once we successfuly loaded the configuration, every processes were marked as old workers. To fix this, the PROC_O_LEAVING flag is set only on the processes which have a number of reloads greater than the current processes. --- src/mworker.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/mworker.c b/src/mworker.c index a14a84093..ac1177f4c 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -134,13 +134,14 @@ void mworker_proc_list_to_env() int mworker_env_to_proc_list() { char *msg, *token = NULL, *s1; + struct mworker_proc *child; + int minreloads = INT_MAX; /* minimum number of reloads to chose which processes are "current" ones */ msg = getenv("HAPROXY_PROCESSES"); if (!msg) return 0; while ((token = strtok_r(msg, "|", &s1))) { - struct mworker_proc *child; char *subtoken = NULL; char *s2; @@ -176,6 +177,9 @@ int mworker_env_to_proc_list() } else if (strncmp(subtoken, "reloads=", 8) == 0) { /* we only increment the number of asked reload */ child->reloads = atoi(subtoken+8); + + if (child->reloads < minreloads) + minreloads = child->reloads; } else if (strncmp(subtoken, "failedreloads=", 14) == 0) { child->failedreloads = atoi(subtoken+14); } else if (strncmp(subtoken, "timestamp=", 10) == 0) { @@ -187,15 +191,19 @@ int mworker_env_to_proc_list() } } if (child->pid) { - /* this is a process inherited from a reload that should be leaving */ - child->options |= PROC_O_LEAVING; - LIST_APPEND(&proc_list, &child->list); } else { mworker_free_child(child); } } + /* set the leaving processes once we know which number of reloads are the current processes */ + + list_for_each_entry(child, &proc_list, list) { + if (child->reloads > minreloads) + child->options |= PROC_O_LEAVING; + } + unsetenv("HAPROXY_PROCESSES"); return 0;