]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: resolvers: Wait a bit before calling the xprt prepare_srv
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 29 May 2026 17:38:03 +0000 (19:38 +0200)
committerOlivier Houchard <cognet@ci0.org>
Fri, 29 May 2026 17:20:23 +0000 (19:20 +0200)
We can't call call the prepare_srv() method too early, because it needs
global.nbthreads to be properly set, which won't be true at post_parse
time. So instead, make it so that code runs later, as a post_check
function, when it will be safe to do so.

This should be backported up to 2.8.
This should fix github issue #3402

src/resolvers.c

index bb07ae566987af8447ef82d3778735a52dfd959b..f646e6aa7e2f13eebf11e83f37ca83152ac921cc 100644 (file)
@@ -4055,21 +4055,21 @@ err:
        return ERR_NONE;
 }
 
-int cfg_post_parse_resolvers()
+static int cfg_post_check_resolvers(void)
 {
-       int err_code = 0;
+       struct resolvers *r;
        struct server *srv;
+       int err_code = 0;
 
-       if (curr_resolvers) {
-
+       list_for_each_entry(r, &sec_resolvers, list) {
                /* prepare forward server descriptors */
-               if (curr_resolvers->px) {
-                       srv = curr_resolvers->px->srv;
+               if (r->px) {
+                       srv = r->px->srv;
                        while (srv) {
                                /* init ssl if needed */
                                if (srv->use_ssl == 1 && xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) {
                                        if (xprt_get(XPRT_SSL)->prepare_srv(srv)) {
-                                               ha_alert("unable to prepare SSL for server '%s' in resolvers section '%s'.\n", srv->id, curr_resolvers->id);
+                                               ha_alert("unable to prepare SSL for server '%s' in resolvers section '%s'.\n", srv->id, r->id);
                                                err_code |= ERR_ALERT | ERR_FATAL;
                                                break;
                                        }
@@ -4078,7 +4078,6 @@ int cfg_post_parse_resolvers()
                        }
                }
        }
-       curr_resolvers = NULL;
        return err_code;
 }
 
@@ -4130,8 +4129,9 @@ static struct cfg_kw_list cfg_kws = {ILH, {
 
 INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
 
-REGISTER_CONFIG_SECTION("resolvers",      cfg_parse_resolvers, cfg_post_parse_resolvers);
+REGISTER_CONFIG_SECTION("resolvers",      cfg_parse_resolvers, NULL);
 REGISTER_POST_DEINIT(resolvers_deinit);
+REGISTER_POST_CHECK(cfg_post_check_resolvers);
 REGISTER_CONFIG_POSTPARSER("dns runtime resolver", resolvers_finalize_config);
 REGISTER_PRE_CHECK(resolvers_create_default);