Skip to content

Commit

Permalink
fix(clustering/rpc): dont start too many timers for sync (#14089)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Jan 8, 2025
1 parent df6cc59 commit 3636949
Showing 1 changed file with 12 additions and 2 deletions.
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

1 comment on commit 3636949

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:3636949548631c33e6ac9d6e07e144d078fc64b9
Artifacts available https://github.com/Kong/kong/actions/runs/12663845616

Please sign in to comment.