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 23, 2018
1 parent 3422f16 commit 0efdec8
Showing 1 changed file with 6 additions and 1 deletion.
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 0efdec8

Please sign in to comment.