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

fix(least-conn) change cleanup order #126

Merged
merged 1 commit into from
Mar 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Release process:
4. commit and tag the release
5. upload rock to LuaRocks

### unreleased

- Fix: potential synchronisation issue in the least-connections balancer.
[PR 126](https://github.com/Kong/lua-resty-dns-client/pull/126)

### 5.2.2 (11-Mar-2021)

- Fix: do not iterate over all the search domains when resolving an unambiguous
Expand Down
18 changes: 10 additions & 8 deletions src/resty/dns/balancer/least_connections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ function lcAddr:setState(available)
end


-- disabling the address, so delete from binaryHeap
function lcAddr:disable()
self.host.balancer.binaryHeap:remove(self)
self.super.disable(self)
end


function lc:newAddress(addr)
addr = self.super.newAddress(self, addr)

Expand All @@ -89,12 +96,6 @@ function lc:newAddress(addr)
end


-- removing the address, so delete from binaryHeap
function lc:onRemoveAddress(address)
self.binaryHeap:remove(address)
end



function lc:getPeer(cacheOnly, handle, hashValue)
if handle then
Expand All @@ -113,7 +114,7 @@ function lc:getPeer(cacheOnly, handle, hashValue)
handle.retryCount = 0
end

local address, ip, port, host, reinsert
local address, ip, port, host
while true do
if not self.healthy then
-- Balancer unhealthy, nothing we can do.
Expand All @@ -126,6 +127,7 @@ function lc:getPeer(cacheOnly, handle, hashValue)

-- go and find the next `address` object according to the LB policy
do
local reinsert
repeat
if address then
-- this address we failed before, so temp store it and pop it from
Expand All @@ -151,7 +153,7 @@ function lc:getPeer(cacheOnly, handle, hashValue)
local addr = reinsert[i]
self.binaryHeap:insert((addr.connectionCount + 1) / addr.weight, addr)
end
reinsert = nil
reinsert = nil -- luacheck: ignore
end
end

Expand Down