From: Remi Gacogne Date: Fri, 27 Jun 2025 14:09:18 +0000 (+0200) Subject: dnsdist-resolver: Fix a bug when we get new IPs for a server X-Git-Tag: rec-5.3.0-alpha2~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e306ec7a085282893b93214a75ba3aac4d9435b4;p=thirdparty%2Fpdns.git dnsdist-resolver: Fix a bug when we get new IPs for a server The `dnsdist-resolver` script regularly checks the IPs corresponding to a backend `hostname`, and updates our backend accordingly: - if an IP we previously received vanishes, it removes the backend corresponding to that IP - if a new IP shows up, it adds a new backend The existing code tries to avoid some work by keeping track of the number of IPs associated to a given server, skipping the comparisons of recently received IPs to existing ones if the number did not change. This unfortunately does not work well if we get the same number of IPs but with different IPs in the set. This caused some backends to never get removed and stay along as ghosts, as well as some new IPs to never be picked up. Signed-off-by: Remi Gacogne --- diff --git a/dockerdata/dnsdist-resolver.lua b/dockerdata/dnsdist-resolver.lua index 16c82fc9d4..be8edd3ebf 100644 --- a/dockerdata/dnsdist-resolver.lua +++ b/dockerdata/dnsdist-resolver.lua @@ -15,7 +15,6 @@ _M.verbose = false -- key = name -- value = {address, serverObject} (should make these named members) local ourservers = {} -local ourcount = {} -- Global variable for store results for getAddressInfo() function local resout = {} @@ -109,39 +108,21 @@ function _M.maintenance() end end - -- init our current count - if ourcount[name] == nil then - ourcount[name] = #ips - end - - -- increase our current count if necessary - if #ips > ourcount[name] then - ourcount[name] = #ips - if _M.verbose then - infolog("increasing count to " .. ourcount[name] .. " for " .. name) - end - end - - -- remove servers when we've lost ips - if #ips < ourcount[name] then - for ourserver, server in pairs(ourservers) do - -- check if we match the prefix and the ip is gone - if ourserver:find(name, 1, true) == 1 and has_value(ips, server[1]) == false then - ourcount[name] = #ips - if _M.verbose then - infolog("ip address not found anymore " .. server[1]) - infolog("decreasing count to " .. ourcount[name]) - end - removeServer(ourserver) + -- remove servers if they are no longer present + for ourserver, server in pairs(ourservers) do + -- check if we match the prefix and the ip is gone + if ourserver:find(name, 1, true) == 1 and has_value(ips, server[1]) == false then + if _M.verbose then + infolog("ip address not found anymore " .. server[1]) end + removeServer(ourserver) end - else - for _, ip in ipairs(ips) do - -- it has IPs - if _M.servers[name] ~= nil then - -- we want this server - setServer(name, ip) - end + end + for _, ip in ipairs(ips) do + -- it has IPs + if _M.servers[name] ~= nil then + -- we want this server + setServer(name, ip) end end end