Skip to content

Commit a3e2a6f

Browse files
committed
fix: release checker when nodes are nil
1 parent a851952 commit a3e2a6f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

apisix/upstream.lua

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ function _M.set_by_route(route, api_ctx)
293293

294294
local new_nodes, err = dis.nodes(up_conf.service_name, up_conf.discovery_args)
295295
if not new_nodes then
296+
release_checker(up_conf.parent)
296297
return HTTP_CODE_UPSTREAM_UNAVAILABLE, "no valid upstream node: " .. (err or "nil")
297298
end
298299

t/discovery/reset-healthchecker.t

+54
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,57 @@ GET /t
167167
--- no_error_log
168168
unhealthy TCP increment (10/30)
169169
--- error_code: 503
170+
171+
172+
173+
=== TEST 3: Validate healthchecker deletion on node count returned is nil
174+
--- http_config
175+
server {
176+
listen 3000 ;
177+
location / {
178+
return 200 'ok';
179+
}
180+
}
181+
--- apisix_yaml
182+
routes:
183+
-
184+
uris:
185+
- /
186+
upstream_id: 1
187+
--- config
188+
location /t {
189+
content_by_lua_block {
190+
local t = require("lib.test_admin").test
191+
local discovery = require("apisix.discovery.init").discovery
192+
discovery.mock = {
193+
nodes = function()
194+
return {
195+
{host = "127.0.0.1", port = 3000, weight = 50},
196+
{host = "127.0.0.1", port = 8000, weight = 50},
197+
}
198+
end
199+
}
200+
local http = require "resty.http"
201+
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/"
202+
local httpc = http.new()
203+
local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false})
204+
ngx.sleep(5)
205+
discovery.mock = {
206+
nodes = function()
207+
return nil
208+
end
209+
}
210+
local http = require "resty.http"
211+
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/"
212+
local httpc = http.new()
213+
local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false})
214+
ngx.status = res.status
215+
ngx.sleep(5)
216+
}
217+
}
218+
--- request
219+
GET /t
220+
--- timeout: 22
221+
--- no_error_log
222+
unhealthy TCP increment (10/30)
223+
--- error_code: 503

0 commit comments

Comments
 (0)