Merge pull request #6600 from nic-6443/backend-sync-503-fix
Bugfix: some requests fail with 503 when nginx reload
This commit is contained in:
commit
7732aec3c4
2 changed files with 66 additions and 16 deletions
|
|
@ -107,6 +107,12 @@ local function sync_backend(backend)
|
|||
return
|
||||
end
|
||||
|
||||
if is_backend_with_external_name(backend) then
|
||||
backend = resolve_external_names(backend)
|
||||
end
|
||||
|
||||
backend.endpoints = format_ipv6_endpoints(backend.endpoints)
|
||||
|
||||
local implementation = get_implementation(backend)
|
||||
local balancer = balancers[backend.name]
|
||||
|
||||
|
|
@ -126,24 +132,21 @@ local function sync_backend(backend)
|
|||
return
|
||||
end
|
||||
|
||||
if is_backend_with_external_name(backend) then
|
||||
backend = resolve_external_names(backend)
|
||||
end
|
||||
|
||||
backend.endpoints = format_ipv6_endpoints(backend.endpoints)
|
||||
|
||||
balancer:sync(backend)
|
||||
end
|
||||
|
||||
local function sync_backends_with_external_name()
|
||||
for _, backend_with_external_name in pairs(backends_with_external_name) do
|
||||
sync_backend(backend_with_external_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function sync_backends()
|
||||
local raw_backends_last_synced_at = configuration.get_raw_backends_last_synced_at()
|
||||
ngx.update_time()
|
||||
local current_timestamp = ngx.time()
|
||||
if current_timestamp - backends_last_synced_at < BACKENDS_FORCE_SYNC_INTERVAL
|
||||
and raw_backends_last_synced_at <= backends_last_synced_at then
|
||||
for _, backend_with_external_name in pairs(backends_with_external_name) do
|
||||
sync_backend(backend_with_external_name)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -161,12 +164,13 @@ local function sync_backends()
|
|||
|
||||
local balancers_to_keep = {}
|
||||
for _, new_backend in ipairs(new_backends) do
|
||||
sync_backend(new_backend)
|
||||
balancers_to_keep[new_backend.name] = balancers[new_backend.name]
|
||||
if is_backend_with_external_name(new_backend) then
|
||||
local backend_with_external_name = util.deepcopy(new_backend)
|
||||
backends_with_external_name[backend_with_external_name.name] = backend_with_external_name
|
||||
else
|
||||
sync_backend(new_backend)
|
||||
end
|
||||
balancers_to_keep[new_backend.name] = true
|
||||
end
|
||||
|
||||
for backend_name, _ in pairs(balancers) do
|
||||
|
|
@ -272,11 +276,12 @@ local function get_balancer()
|
|||
end
|
||||
|
||||
function _M.init_worker()
|
||||
-- when worker starts, sync backends without delay
|
||||
-- we call it in timer because for endpoints that require
|
||||
-- when worker starts, sync non ExternalName backends without delay
|
||||
sync_backends()
|
||||
-- we call sync_backends_with_external_name in timer because for endpoints that require
|
||||
-- DNS resolution it needs to use socket which is not available in
|
||||
-- init_worker phase
|
||||
local ok, err = ngx.timer.at(0, sync_backends)
|
||||
local ok, err = ngx.timer.at(0, sync_backends_with_external_name)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to create timer: ", err)
|
||||
end
|
||||
|
|
@ -285,6 +290,11 @@ function _M.init_worker()
|
|||
if not ok then
|
||||
ngx.log(ngx.ERR, "error when setting up timer.every for sync_backends: ", err)
|
||||
end
|
||||
ok, err = ngx.timer.every(BACKENDS_SYNC_INTERVAL, sync_backends_with_external_name)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "error when setting up timer.every for sync_backends_with_external_name: ",
|
||||
err)
|
||||
end
|
||||
end
|
||||
|
||||
function _M.rewrite()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue