From af9948cc16ffea9f945bbd0539230fe0665b1b21 Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Thu, 19 May 2022 16:49:49 +0800 Subject: [PATCH] fix(clustering) localize config_version to avoid race condition from yield --- kong/clustering/wrpc_data_plane.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kong/clustering/wrpc_data_plane.lua b/kong/clustering/wrpc_data_plane.lua index cda078b9982..f0cf2495e22 100644 --- a/kong/clustering/wrpc_data_plane.lua +++ b/kong/clustering/wrpc_data_plane.lua @@ -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