Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
fix(balancer) fix ttl-0 records issues
Browse files Browse the repository at this point in the history
* 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 Kong/kong#5477
  • Loading branch information
Tieske committed Jan 24, 2020
1 parent 6c1bb6c commit b0af960
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/resty/dns/balancer/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b0af960

Please sign in to comment.