From 00f585661858d5f67574236adfe67e2b2d816939 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 23 Jan 2020 19:51:30 +0100 Subject: [PATCH] fix(balancer) fix ttl-0 records issues * the previous record was not properly detected as a ttl=0 record by checking on the __ttl0flag we now do * since the "fake" SRV record wasn't updated with a new expiry time the expiry-check-timer would keep updating that record every second Fixes Kong issue https://github.com/Kong/kong/issues/5477 --- README.md | 10 ++++++++++ src/resty/dns/balancer/base.lua | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b53e9d..d98da63 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,16 @@ History Versioning is strictly based on [Semantic Versioning](https://semver.org/) +### 4.1.x (xx-xxx-2020) + +- Fix: fix ttl-0 records issues with the balancer, see Kong issue + https://github.com/Kong/kong/issues/5477 + * the previous record was not properly detected as a ttl=0 record + by checking on the `__ttl0flag` we now do + * since the "fake" SRV record wasn't updated with a new expiry + time the expiry-check-timer would keep updating that record + every second + ### 4.1.2 (10-Dec-2019) - Fix: handle cases when `lastQuery` is `nil`, see [PR 81](https://github.com/Kong/lua-resty-dns-client/pull/81) diff --git a/src/resty/dns/balancer/base.lua b/src/resty/dns/balancer/base.lua index 48b0aa9..54d0bca 100644 --- a/src/resty/dns/balancer/base.lua +++ b/src/resty/dns/balancer/base.lua @@ -413,7 +413,8 @@ local function update_dns_result(self, newQuery, dns) -- So if we get a ttl=0 twice in a row (the old one, and the new one), we update it. And -- if the very first request ever reports ttl=0 (we assume we're not hitting the edgecase -- in that case) - if (newQuery[1] or empty).ttl == 0 and ((oldQuery[1] or empty).ttl or 0) == 0 then + if (newQuery[1] or empty).ttl == 0 and + (((oldQuery[1] or empty).ttl or 0) == 0 or oldQuery.__ttl0Flag) then -- ttl = 0 means we need to lookup on every request. -- To enable lookup on each request we 'abuse' a virtual SRV record. We set the ttl -- to `ttl0Interval` seconds, and set the `target` field to the hostname that needs @@ -424,6 +425,8 @@ local function update_dns_result(self, newQuery, dns) -- so we fix them at the `nodeWeight` property, as with A and AAAA records. if oldQuery.__ttl0Flag then -- still ttl 0 so nothing changed + oldQuery.touched = time() + oldQuery.expire = oldQuery.touched + self.balancer.ttl0Interval ngx_log(ngx_DEBUG, self.log_prefix, "no dns changes detected for ", self.hostname, ", still using ttl=0") return true