BUG/MEDIUM: resolvers: Reset server address and port for obselete SRV records
When a SRV record expires, the ip/port assigned to the associated server are
now removed. Otherwise, the server is stopped but keeps its ip/port while
the server hostname is removed. It is confusing when the servers state are
retrieve on the CLI and may be a problem if saved in a server-state
file. Because the reload may fail because of this inconsistency.
Here is an example:
* Declare a server template in a backend, using the resolver <dns>
server-template test 2 _http._tcp.example.com resolvers dns check
* 2 SRV records are announced with the corresponding additional
records. Thus, 2 servers are filled. Here is the "show servers state"
output :
2 frt 1 test1 192.168.1.1 2 64 0 1 2 15 3 4 6 0 0 0 http1.example.com 8001 _http._tcp.example.com 0 0 - - 0
2 frt 2 test2 192.168.1.2 2 64 0 1 1 15 3 4 6 0 0 0 http2.example.com 8002 _http._tcp.example.com 0 0 - - 0
* Then, one additional record is removed (or a SRV record is removed, the
result is the same). Here is the new "show servers state" output :
2 frt 1 test1 192.168.1.1 2 64 0 1 38 15 3 4 6 0 0 0 http1.example.com 8001 _http._tcp.example.com 0 0 - - 0
2 frt 2 test2 192.168.1.2 0 96 0 1 19 15 3 0 14 0 0 0 - 8002 _http._tcp.example.com 0 0 - - 0
On reload, if a server-state file is used, this leads to undefined behaviors
depending on the configuration.
This patch should be backported as far as 2.0.
(cherry picked from commit 52d4d3010991e851b8e9e4d9f923ad1f74d30d69)
[cf: Changes applied in src/dns.c]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/dns.c b/src/dns.c
index 5a572e1..fa1a246 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -625,6 +625,8 @@
srv->hostname = NULL;
srv->hostname_dn = NULL;
srv->hostname_dn_len = 0;
+ memset(&srv->addr, 0, sizeof(srv->addr));
+ srv->svc_port = 0;
dns_unlink_resolution(srv->dns_requester);
}
HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
diff --git a/src/server.c b/src/server.c
index daa9d4a..b5a5554 100644
--- a/src/server.c
+++ b/src/server.c
@@ -3964,6 +3964,8 @@
s->hostname = NULL;
s->hostname_dn = NULL;
s->hostname_dn_len = 0;
+ memset(&s->addr, 0, sizeof(s->addr));
+ s->svc_port = 0;
dns_unlink_resolution(s->dns_requester);
}
HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);