Skip to content

Commit

Permalink
fix: last_err can be nil when the reconnection is successful (#8377)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored Nov 30, 2022
1 parent 3d5128d commit 2f0b7da
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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

0 comments on commit 2f0b7da

Please sign in to comment.