Hello,
In #48 it was reported that when using the server-template directive combined with an SRV record that HAProxy would always set the weight to "1" regardless of what the SRV record contains. It was found that in an attempt to force a minimum value of "1" actually ended up forcing "1" in all situations. This was due to an improper equation: ( x / 256 ) + 1 This patch should be backported to 1.8 and 1.9 Thanks, -- Daniel
>From b9c2d037b0b3cf06a7908bcaa4949a29245574ca Mon Sep 17 00:00:00 2001 From: Daniel Corbett <[email protected]> Date: Wed, 16 Oct 2019 23:13:20 -0400 Subject: [PATCH] BUG/MEDIUM: dns: Use weight as specified in SRV record In #48 it was reported that when using the server-template directive combined with an SRV record that HAProxy would always set the weight to "1" regardless of what the SRV record contains. It was found that in an attempt to force a minimum value of "1" actually ended up forcing "1" in all situations. This was due to an improper equation: ( x / 256) + 1 This patch should be backported to 1.8 and 1.9 --- src/dns.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dns.c b/src/dns.c index 0ce6e8302..8a71bd495 100644 --- a/src/dns.c +++ b/src/dns.c @@ -546,7 +546,12 @@ static void dns_check_dns_response(struct dns_resolution *res) /* Make sure weight is at least 1, so * that the server will be used. */ - ha_weight = item->weight / 256 + 1; + if (item->weight > 1 && item->weight <= 256) { + ha_weight = item->weight; + } + else { + ha_weight = 1; + } if (srv->uweight != ha_weight) { char weight[9]; @@ -593,7 +598,12 @@ static void dns_check_dns_response(struct dns_resolution *res) /* Make sure weight is at least 1, so * that the server will be used. */ - ha_weight = item->weight / 256 + 1; + if (item->weight > 1 && item->weight <= 256) { + ha_weight = item->weight; + } + else { + ha_weight = 1; + } snprintf(weight, sizeof(weight), "%d", ha_weight); server_parse_weight_change_request(srv, weight); -- 2.17.1

