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

fix(client) ensure validTtl override does not interfere with TTL of #134

Merged
merged 2 commits into from
Jul 6, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ Release process:
4. commit and tag the release
5. upload rock to LuaRocks

### 6.0.1 (22-Jun-2021)
### 6.0.x (unreleased)

- Fix: `validTtl` should not be used for host-file entries.
[PR 134](https://github.com/Kong/lua-resty-dns-client/pull/134)

### 6.0.1 (22-Jun-2021)

- Performance: reduce amount of timers on init_worker. [PR 130](https://github.com/Kong/lua-resty-dns-client/pull/130)

Expand Down
27 changes: 27 additions & 0 deletions spec/client_cache_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,31 @@ describe("[DNS client cache]", function()

end)


describe("hosts entries", function()
-- hosts file names are cached for 10 years, verify that
-- it is not overwritten with validTtl settings.
-- Regressions reported in https://github.com/Kong/kong/issues/7444
local lrucache, mock_records, config -- luacheck: ignore
before_each(function()
config = {
nameservers = { "8.8.8.8" },
hosts = {"127.0.0.1 myname.lan"},
resolvConf = {},
validTtl = 0.1,
staleTtl = 0,
}

assert(client.init(config))
lrucache = client.getcache()
end)

it("entries from hosts file ignores validTtl overrides, Kong/kong #7444", function()
ngx.sleep(0.2) -- must be > validTtl + staleTtl

record = client.getcache():get("1:myname.lan")
assert.equal("127.0.0.1", record[1].address)
end)
end)

end)
9 changes: 6 additions & 3 deletions src/resty/dns/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,6 @@ _M.init = function(options)
staleTtl = options.staleTtl or 4
log(DEBUG, PREFIX, "staleTtl = ", staleTtl)

validTtl = options.validTtl
log(DEBUG, PREFIX, "validTtl = ", tostring(validTtl))

cacheSize = options.cacheSize or 10000 -- default set here to be able to reset the cache
noSynchronisation = options.noSynchronisation
log(DEBUG, PREFIX, "noSynchronisation = ", tostring(noSynchronisation))
Expand Down Expand Up @@ -543,6 +540,12 @@ _M.init = function(options)
end
end

-- see: https://github.com/Kong/kong/issues/7444
-- since the validTtl affects ttl of caching entries,
-- only set it after hosts entries are inserted
-- so that the 10 years of TTL for hosts file actually takes effect.
validTtl = options.validTtl
log(DEBUG, PREFIX, "validTtl = ", tostring(validTtl))

-- Deal with the `resolv.conf` file

Expand Down