Skip to content

Commit

Permalink
fix(clustering): handle race cond for new DP and new cfg (#9616)
Browse files Browse the repository at this point in the history
* fix(clustering): handle race cond for new DP and new cfg
* docs(changelog): add changelog entry for #9616

Co-authored-by: Michael Martin <[email protected]>
  • Loading branch information
StarlightIbuki and flrgh authored Oct 26, 2022
1 parent 9bc3c73 commit d2365cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
- Fixed an issue with error-handling and process cleanup in `kong start`.
[#9337](https://github.com/Kong/kong/pull/9337)

#### Hybrid Mode

- Fixed a race condition that can cause configuration push events to be dropped
when the first data-plane connection is established with a control-plane
worker.
[#9616](https://github.com/Kong/kong/pull/9616)

#### CLI

- Fix slow CLI performance due to pending timer jobs
Expand Down
6 changes: 6 additions & 0 deletions kong/clustering/control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local sub = string.sub
local gsub = string.gsub
local deflate_gzip = utils.deflate_gzip
local isempty = require("table.isempty")
local sleep = ngx.sleep

local calculate_config_hash = require("kong.clustering.config_helper").calculate_config_hash

Expand Down Expand Up @@ -551,6 +552,11 @@ local function push_config_loop(premature, self, push_config_semaphore, delay)
if ok then
if isempty(self.clients) then
ngx_log(ngx_DEBUG, _log_prefix, "skipping config push (no connected clients)")
sleep(1)
-- re-queue the task. wait until we have clients connected
if push_config_semaphore:count() <= 0 then
push_config_semaphore:post()
end

else
ok, err = pcall(self.push_config, self)
Expand Down
6 changes: 6 additions & 0 deletions kong/clustering/wrpc_control_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local ngx_time = ngx.time
local ngx_var = ngx.var
local timer_at = ngx.timer.at
local isempty = require("table.isempty")
local sleep = ngx.sleep

local plugins_list_to_map = clustering_utils.plugins_list_to_map
local deflate_gzip = utils.deflate_gzip
Expand Down Expand Up @@ -316,6 +317,11 @@ local function push_config_loop(premature, self, push_config_semaphore, delay)
if ok then
if isempty(self.clients) then
ngx_log(ngx_DEBUG, _log_prefix, "skipping config push (no connected clients)")
sleep(1)
-- re-queue the task. wait until we have clients connected
if push_config_semaphore:count() <= 0 then
push_config_semaphore:post()
end

else
ok, err = pcall(self.push_config, self)
Expand Down

0 comments on commit d2365cb

Please sign in to comment.