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 accidental ttl=0 switches
Browse files Browse the repository at this point in the history
See #51

Some servers will report ttl=0 when they are on the very edge
of their own cached ttl. This should never happen for a record
that has a non-0 ttl.

This fix makes sure we require ttl=0 reported twice in a row before
we switch the loadbalancer.

Fixes #51
  • Loading branch information
Tieske committed Aug 27, 2018
1 parent ae73c44 commit c010840
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit c010840

Please sign in to comment.