Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runloop) reschedule rebuild timers after running them #8634

Merged
merged 2 commits into from
Apr 4, 2022
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@

### Fixes

#### Core

- Only reschedule router and plugin iterator timers after finishing previous
execution, avoiding unnecessary concurrent executions.
[#8634](https://github.com/Kong/kong/pull/8634)

## [2.8.0]

### Deprecations
Expand Down
34 changes: 27 additions & 7 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ local exit = ngx.exit
local exec = ngx.exec
local header = ngx.header
local timer_at = ngx.timer.at
local timer_every = ngx.timer.every
local subsystem = ngx.config.subsystem
local clear_header = ngx.req.clear_header
local http_version = ngx.req.http_version
Expand Down Expand Up @@ -1113,7 +1112,7 @@ return {
on_timeout = "return_true",
}

timer_every(worker_state_update_frequency, function(premature)
local function rebuild_router_timer(premature)
if premature then
return
end
Expand All @@ -1126,24 +1125,45 @@ return {
if not ok then
log(ERR, "could not rebuild router via timer: ", err)
end
end)

local _, err = timer_at(worker_state_update_frequency, rebuild_router_timer)
if err then
log(ERR, "could not schedule timer to rebuild router: ", err)
end
end

local _, err = timer_at(worker_state_update_frequency, rebuild_router_timer)
if err then
log(ERR, "could not schedule timer to rebuild router: ", err)
end

local plugins_iterator_async_opts = {
name = "plugins_iterator",
timeout = 0,
on_timeout = "return_true",
}

timer_every(worker_state_update_frequency, function(premature)
local function rebuild_plugins_iterator_timer(premature)
if premature then
return
end

local ok, err = rebuild_plugins_iterator(plugins_iterator_async_opts)
if not ok then
local _, err = rebuild_plugins_iterator(plugins_iterator_async_opts)
if err then
log(ERR, "could not rebuild plugins iterator via timer: ", err)
end
end)

local _, err = timer_at(worker_state_update_frequency, rebuild_plugins_iterator_timer)
if err then
log(ERR, "could not schedule timer to rebuild plugins iterator: ", err)
end
end

local _, err = timer_at(worker_state_update_frequency, rebuild_plugins_iterator_timer)
if err then
log(ERR, "could not schedule timer to rebuild plugins iterator: ", err)
end

end
end,
after = NOOP,
Expand Down
5 changes: 4 additions & 1 deletion kong/runloop/plugins_iterator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ function PluginsIterator.new(version)
end

if new_version ~= version then
return nil, "plugins iterator was changed while rebuilding it"
-- the plugins iterator rebuild is being done by a different process at
-- the same time, stop here and let the other one go for it
kong.log.info("plugins iterator was changed while rebuilding it")
return
end
end

Expand Down