Skip to content

Commit

Permalink
fix(clustering) localize config_version to avoid race condition from (#…
Browse files Browse the repository at this point in the history
…8818)

yield

`update_config` can yield, so we need to cache fields in `self`, otherwise it might got updated (on L89) before we read it (on L208), and causes L202 become false next time, thus prevent next ConfigSync being executed. This probably become more visiable as we introduce more `yield` from #8800.
  • Loading branch information
fffonion committed May 19, 2022
1 parent 6558e99 commit f84bdde
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kong/clustering/wrpc_data_plane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ function _M:communicate(premature)
end
local config_table = self.next_config
local config_hash = self.next_hash
local config_version = self.next_config_version
local hashes = self.next_hashes
if config_table and self.next_config_version > last_config_version then
ngx_log(ngx_INFO, _log_prefix, "received config #", self.next_config_version, log_suffix)
if config_table and config_version > last_config_version then
ngx_log(ngx_INFO, _log_prefix, "received config #", config_version, log_suffix)

local pok, res
pok, res, err = xpcall(self.update_config, debug.traceback, self, config_table, config_hash, true, hashes)
if pok then
last_config_version = self.next_config_version
last_config_version = config_version
if not res then
ngx_log(ngx_ERR, _log_prefix, "unable to update running config: ", err)
end
Expand Down

0 comments on commit f84bdde

Please sign in to comment.