]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: haproxy: abort config parsing on fatal errors for post parsing hooks
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 27 Aug 2025 10:27:53 +0000 (12:27 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 27 Aug 2025 10:54:13 +0000 (12:54 +0200)
When pre-check and post-check postparsing hooks= are evaluated in
step_init_2() potential fatal errors are ignored during the iteration
and are only taken into account at the end of the loop. This is not ideal
because some errors (ie: memory errors) could cause multiple alert
messages in a row, which could make troubleshooting harder for the user.

Let's stop as soon as a fatal error is encountered for post parsing
hooks, as we use to do everywhere else.

src/haproxy.c

index 52d93c228a064f909cb003f76c18b5808ca7788c..7a3b511eaca65e92fc6609894070fe7d63e882b5 100644 (file)
@@ -2061,12 +2061,12 @@ static void step_init_2(int argc, char** argv)
        /* destroy unreferenced defaults proxies  */
        proxy_destroy_all_unref_defaults();
 
-       list_for_each_entry(prcf, &pre_check_list, list)
+       list_for_each_entry(prcf, &pre_check_list, list) {
                err_code |= prcf->fct();
-
-       if (err_code & (ERR_ABORT|ERR_FATAL)) {
-               ha_alert("Fatal errors found in configuration.\n");
-               exit(1);
+               if (err_code & (ERR_ABORT|ERR_FATAL)) {
+                       ha_alert("Fatal errors found in configuration.\n");
+                       exit(1);
+               }
        }
 
        /* update the ready date that will be used to count the startup time
@@ -2119,17 +2119,24 @@ static void step_init_2(int argc, char** argv)
                        continue;
 
                list_for_each_entry(pscf, &post_server_check_list, list) {
-                       for (srv = px->srv; srv; srv = srv->next)
+                       for (srv = px->srv; srv; srv = srv->next) {
                                err_code |= pscf->fct(srv);
+                               if (err_code & (ERR_ABORT|ERR_FATAL)) {
+                                       ha_alert("Fatal errors found in configuration.\n");
+                                       exit(1);
+                               }
+                       }
                }
-               list_for_each_entry(ppcf, &post_proxy_check_list, list)
+               list_for_each_entry(ppcf, &post_proxy_check_list, list) {
                        err_code |= ppcf->fct(px);
+                       if (err_code & (ERR_ABORT|ERR_FATAL)) {
+                               ha_alert("Fatal errors found in configuration.\n");
+                               exit(1);
+                       }
+
+               }
                px->flags |= PR_FL_CHECKED;
        }
-       if (err_code & (ERR_ABORT|ERR_FATAL)) {
-               ha_alert("Fatal errors found in configuration.\n");
-               exit(1);
-       }
 
        err_code |= pattern_finalize_config();
        if (err_code & (ERR_ABORT|ERR_FATAL)) {