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

Commit

Permalink
fix(base) fix issue with 100% CPU
Browse files Browse the repository at this point in the history
Busy-loop created when renewing expired dns records
  • Loading branch information
Tieske committed Jan 21, 2021
1 parent 6b6a33f commit 7051700
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ Release process:
4. commit and tag the release
5. upload rock to LuaRocks

### 5.2.1 (21-Jan-2021)

- Fix: balancer DNS updates could go into a busy loop upon renewal. Reported as
[Kong issue #6739](https://github.com/Kong/kong/issues/6739),
fixed with [PR 116](https://github.com/Kong/lua-resty-dns-client/pull/116).

### 5.2.0 (7-Jan-2021)

- Fix: now a single timer is used to check for expired records instead of one
per host, significantly reducing the number of resources required for DNS
resolution. [PR 112](https://github.com/Kong/lua-resty-dns-client/pull/112)


### 5.1.1 (7-Oct-2020)

- Dependency: Bump lua-resty-timer to 1.0
Expand Down
9 changes: 8 additions & 1 deletion src/resty/dns/balancer/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,14 @@ local function schedule_dns_renewal(host)
local record_expiry = (host.lastQuery or EMPTY).expire or 0
local key = host.balancer.id .. ":" .. host.hostname .. ":" .. host.port

local new_renew_at = record_expiry + 0.05 -- ensure expired, but within stale_ttl
-- because of the DNS cache, a stale record will most likely be returned by the
-- client, and queryDns didn't do anything, other than start a background renewal
-- query. In that case record_expiry is based on the stale old query (lastQuery)
-- and it will be in the past. So we schedule a renew at least 0.5 seconds in
-- the future, so by then the background query is complete and that second call
-- to queryDns will do the actual updates. Without math.max is would create a
-- busy loop and hang.
local new_renew_at = math.max(ngx.now(), record_expiry) + 0.5
local old_renew_at = renewal_heap:valueByPayload(key)

-- always store the host in the registry, because the same key might be reused
Expand Down

0 comments on commit 7051700

Please sign in to comment.