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

Commit

Permalink
fix(least-conn) change cleanup order
Browse files Browse the repository at this point in the history
remove address from binary heap upon 'disabling' instead of when
'deleting'.
  • Loading branch information
Tieske committed Mar 16, 2021
1 parent 1b5ab72 commit 8bf8056
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 8bf8056

Please sign in to comment.