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

fix(balancer) fix accidental ttl=0 switches #56

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Versioning is strictly based on [Semantic Versioning](https://semver.org/)
`ttl` value of any valid answer received. [Issue 48](https://github.com/Kong/lua-resty-dns-client/issues/48).
- Fix: remove multiline log entries, now encoded as single-line json. [Issue 52](https://github.com/Kong/lua-resty-dns-client/issues/52).
- Fix: always inject a `localhost` value, even if not in `/etc/hosts`. [Issue 54](https://github.com/Kong/lua-resty-dns-client/issues/54).
- Fix: added a workaround for Amazon Route 53 nameservers replying with a
`ttl=0` whilst the record has a non-0 ttl. [Issue 56](https://github.com/Kong/lua-resty-dns-client/issues/56).

### 2.1.0 (21-May-2018) Fixes

Expand Down
7 changes: 6 additions & 1 deletion src/resty/dns/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,12 @@ function objHost:queryDns(cacheOnly)
return true -- exit, nothing changed
end

if (newQuery[1] or empty).ttl == 0 then
-- To detect ttl = 0 we validate both the old and new record. This is done to ensure
-- we do not hit the edgecase of https://github.com/Kong/lua-resty-dns-client/issues/51
-- 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
-- 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 Down