Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: last_err can be nil when the reconnection is successful #8377

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ local function _automatic_fetch(premature, self)
if err ~= self.last_err then
self.last_err = err
self.last_err_time = ngx_time()
else
elseif self.last_err then
if ngx_time() - self.last_err_time >= 30 then
self.last_err = nil
end
Expand Down Expand Up @@ -604,6 +604,12 @@ local function _automatic_fetch(premature, self)
end
end

-- for test
_M.test_automatic_fetch = _automatic_fetch
function _M.inject_sync_data(f)
sync_data = f
end


---
-- Create a new connection to communicate with the control plane.
Expand Down
30 changes: 30 additions & 0 deletions t/core/config_etcd.t
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,33 @@ qr/healthy check use \S+ \w+/
--- grep_error_log_out eval
qr/healthy check use round robin
(healthy check use ngx.shared dict){1,}/



=== TEST 10: last_err can be nil when the reconnection is successful
--- config
location /t {
content_by_lua_block {
local config_etcd = require("apisix.core.config_etcd")
local count = 0
config_etcd.inject_sync_data(function()
if count % 2 == 0 then
count = count + 1
return nil, "has no healthy etcd endpoint available"
else
return true
end
end)
config_etcd.test_automatic_fetch(false, {
running = true,
resync_delay = 1,
})
ngx.say("passed")
}
}
--- request
GET /t
--- error_log
reconnected to etcd
--- response_body
passed