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(clustering/rpc): dont start too many timers for sync #14089

Merged
merged 2 commits into from
Jan 8, 2025
Merged
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
14 changes: 12 additions & 2 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ local sync_once_impl


local function start_sync_once_timer(retry_count)
local ok, err = ngx.timer.at(0, sync_once_impl, retry_count or 0)
local ok, err = kong.timer:at(0, sync_once_impl, retry_count or 0)
if not ok then
return nil, err
end
Expand All @@ -385,6 +385,8 @@ function sync_once_impl(premature, retry_count)

sync_handler()

-- check if "kong.sync.v2.notify_new_version" updates the latest version

local latest_notified_version = ngx.shared.kong:get(CLUSTERING_DATA_PLANES_LATEST_VERSION_KEY)
if not latest_notified_version then
ngx_log(ngx_DEBUG, "no version notified yet")
Expand All @@ -409,7 +411,15 @@ end


function _M:sync_once(delay)
return ngx.timer.at(delay or 0, sync_once_impl, 0)
local name = "rpc_sync_v2_once"
local is_managed = kong.timer:is_managed(name)

-- we are running a sync handler
if is_managed then
return true
end

return kong.timer:named_at(name, delay or 0, sync_once_impl, 0)
end


Expand Down
Loading