Skip to content

Commit

Permalink
fix(clustering/rpc): try sync after rpc is ready (#13901)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored Nov 27, 2024
1 parent b1cf758 commit 23b2ae1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 1 addition & 2 deletions kong/clustering/services/sync/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ local strategy = require("kong.clustering.services.sync.strategies.postgres")
local rpc = require("kong.clustering.services.sync.rpc")


-- TODO: what is the proper value?
local FIRST_SYNC_DELAY = 0.5 -- seconds
local FIRST_SYNC_DELAY = 0.2 -- seconds
local EACH_SYNC_DELAY = 30 -- seconds


Expand Down
22 changes: 20 additions & 2 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,27 @@ function _M:init(manager, is_cp)
end


-- check if rpc connection is ready
local function is_rpc_ready()
for i = 1, 5 do
local res = kong.rpc:get_peers()

-- control_plane is ready
if res["control_plane"] then
return true
end

-- retry later
ngx.sleep(0.1 * i)
end
end


local function do_sync()
if not is_rpc_ready() then
return nil, "rpc is not ready"
end

local ns_deltas, err = kong.rpc:call("control_plane", "kong.sync.v2.get_delta",
{ default =
{ version =
Expand Down Expand Up @@ -394,8 +414,6 @@ end


function _M:sync_once(delay)
--- XXX TODO: check rpc connection is ready

return start_sync_timer(ngx.timer.at, delay or 0)
end

Expand Down

1 comment on commit 23b2ae1

@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:23b2ae112ebfc12a279fb5625d12570f029e71d8
Artifacts available https://github.com/Kong/kong/actions/runs/12042458431

Please sign in to comment.