]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: server/checks: Support healtcheck keyword on default-server lines
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jun 2026 19:53:31 +0000 (21:53 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jun 2026 19:53:32 +0000 (21:53 +0200)
The healthcheck keyword could be parsed on default-server lines but not
copied during server initialization, making it ineffective. But there is
also a true issue by setting it on a default-server. The pseudo server used
to parse the default-server line is not initialized via the new_server()
function, as regular servers. So there is no tcpcheck information inherited
from the proxy. We must take care of that when the "healthcheck" keyword is
parsed to avoid crashes.

This patch must be backported to 3.4.

src/server.c
src/tcpcheck.c

index 23b6322bf718c57acd5362a94eaf65007ed3b6bd..2cf2ac34bb4c791c12bf75ab9094da85f0242339 100644 (file)
@@ -2978,6 +2978,19 @@ void srv_settings_cpy(struct server *srv, const struct server *src, int srv_tmpl
                        srv->check.alpn_len = src->check.alpn_len;
                }
        }
+       if (src->check.tcpcheck && src->check.tcpcheck->healthcheck) {
+               struct tcpcheck *tcpcheck = NULL;
+
+               tcpcheck = calloc(1, sizeof(*tcpcheck));
+               if (tcpcheck) {
+                       LIST_INIT(&tcpcheck->preset_vars);
+                       tcpcheck->healthcheck = strdup(src->check.tcpcheck->healthcheck);
+                       if (tcpcheck->healthcheck == NULL)
+                               ha_free(&tcpcheck);
+               }
+               if (tcpcheck)
+                       srv->check.tcpcheck = tcpcheck;
+       }
 
        if (!(srv->flags & SRV_F_RHTTP))
                srv->check.reuse_pool = src->check.reuse_pool;
index a1ee85f4d0435d49307ed741369e22cfa3d381d5..4d01f2f3b9b4554112edf51d625a842360cee0c5 100644 (file)
@@ -5970,7 +5970,7 @@ static int srv_parse_healthcheck(char **args, int *cur_arg, struct proxy *curpx,
                goto out;
        }
 
-       if (srv->check.tcpcheck->healthcheck) {
+       if (srv->check.tcpcheck && srv->check.tcpcheck->healthcheck) {
                /* a healthcheck section was already defined. Replace it */
                ha_free(&srv->check.tcpcheck->healthcheck);
        }