]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mworker: report status, if daemonized master fails
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 9 Dec 2024 17:56:01 +0000 (18:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2024 20:32:49 +0000 (21:32 +0100)
As daemonization fork happens now very early and before the master-worker
fork, if master or worker processes fail during the initialization, some
critical errors can't be reported to stdout. The launching (parent) process in
such cases exits with 0. This makes an impression, that master and his worker
have successfully started at background, which really complicates the
operations.

In the previous commit a pipe was added to make daemonized child communicate
with his parent. Let's add the same logic to master-worker mode. Up to
receiving the READY message from the worker, master will "forward" it via the
pipe to the launching process. Launching process can obtain master's exit
status, if the master fails to start and nothing has been written in the pipe.

This fix should be backported only in 3.1.

src/cli.c
src/mworker.c

index 1befd8ee0cced92e388f920f36530b2d7f56d601..506e5e45c4d9ed2b76d9198125b3d06cea840be4 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2494,6 +2494,7 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
 {
        struct listener *mproxy_li;
        struct mworker_proc *proc;
+       char *msg = "READY\n";
        int pid;
 
        BUG_ON((strcmp(args[0], "_send_status") != 0),
@@ -2537,6 +2538,15 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
                nb_oldpids = tell_old_pids(oldpids_sig);
        }
 
+       if (daemon_fd[1] != -1) {
+               if (write(daemon_fd[1], msg, strlen(msg)) < 0) {
+                       ha_alert("[%s.main()] Failed to write into pipe with parent process: %s\n", progname, strerror(errno));
+                       exit(1);
+               }
+               close(daemon_fd[1]);
+               daemon_fd[1] = -1;
+       }
+
        load_status = 1;
        ha_notice("Loading success.\n");
 
index 5037d9d70ff8c5abdd388c59e23adc994700e932..9096f0062805733e03eeff541c0f430b02b4c0dd 100644 (file)
@@ -1250,6 +1250,11 @@ void mworker_apply_master_worker_mode(void)
 
                exit(EXIT_FAILURE);
        case 0:
+               if (daemon_fd[1] >= 0) {
+                       close(daemon_fd[1]);
+                       daemon_fd[1] = -1;
+               }
+
                /* This one must not be exported, it's internal! */
                unsetenv("HAPROXY_MWORKER_REEXEC");
                ha_random_jump96(1);