]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: fix -D -W -sf/-st modes
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Tue, 3 Dec 2024 20:13:47 +0000 (21:13 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 6 Dec 2024 11:00:22 +0000 (12:00 +0100)
When a new master process is launched like below:

./haproxy -W -D -p ha.pid -sf $(cat ha.pid)...

The old master process and its workers do not stop. Since the master-worker
refactoring, the code, which sends USR1/TERM to old pids from -sf, is called
only for the standalone mode. In master-worker mode we should receive the READY
message from the newly forked worker at first, in order to be able to terminate
the previous master.

So, to fix this, let's terminate the previous master in _send_status(), where
we parse the READY message from the newly forked worker. And let's continue to
use oldpids array, as it was in 3.0, in order to stop the workers, launched
before the reload.

This patch should be backported only in 3.1.

src/cli.c

index 05baf85ee6ba6c432f19c10994498038ea67664b..e5d8fc562101d9ed5c8fc36cc09a6cb36dd0c006 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2518,14 +2518,6 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
 
                }
        }
-       /* stop previous worker process, if it wasn't signaled during max reloads check */
-       list_for_each_entry(proc, &proc_list, list) {
-               if ((proc->options & PROC_O_TYPE_WORKER) &&
-                       (proc->options & PROC_O_LEAVING) &&
-                       (proc->reloads >= 1)) {
-                       kill(proc->pid, oldpids_sig);
-               }
-       }
 
        /* At this point we are sure, that newly forked worker is started,
         * so we can write our PID in a pidfile, if provided. Master doesn't
@@ -2534,11 +2526,19 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
        if (global.pidfile != NULL)
                handle_pidfile();
 
+       /* either send USR1/TERM to old master, case when we launched as -W -D ... -sf $(cat pidfile),
+        * or send USR1/TERM to old worker processes.
+        */
+       if (nb_oldpids > 0) {
+               nb_oldpids = tell_old_pids(oldpids_sig);
+       }
+
        load_status = 1;
        ha_notice("Loading success.\n");
 
        if (global.tune.options & GTUNE_USE_SYSTEMD)
                sd_notifyf(0, "READY=1\nMAINPID=%lu\nSTATUS=Ready.\n", (unsigned long)getpid());
+
        return 1;
 }