diff --git a/README.md b/README.md index 98d8d0a..1a9283b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/resty/dns/balancer.lua b/src/resty/dns/balancer.lua index e09b777..ee70431 100644 --- a/src/resty/dns/balancer.lua +++ b/src/resty/dns/balancer.lua @@ -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