Skip to content

Commit

Permalink
fix(clustering/rpc): try sync after rpc is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Nov 20, 2024
1 parent 7d2f2c1 commit 991b18c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 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
13 changes: 12 additions & 1 deletion kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,18 @@ end


function _M:sync_once(delay)
--- XXX TODO: check rpc connection is ready
--- check rpc connection is ready
for i = 1, 5 do
local res = kong.rpc:get_peers()

-- control_plane is ready
if res["control_plane"] then
break
end

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

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

0 comments on commit 991b18c

Please sign in to comment.