diff --git a/apisix/upstream.lua b/apisix/upstream.lua index f51c1712fd99..fcf9006c2013 100644 --- a/apisix/upstream.lua +++ b/apisix/upstream.lua @@ -293,6 +293,7 @@ function _M.set_by_route(route, api_ctx) local new_nodes, err = dis.nodes(up_conf.service_name, up_conf.discovery_args) if not new_nodes then + release_checker(up_conf.parent) return HTTP_CODE_UPSTREAM_UNAVAILABLE, "no valid upstream node: " .. (err or "nil") end diff --git a/t/discovery/reset-healthchecker.t b/t/discovery/reset-healthchecker.t index 8612f1fd783c..a6e27ae9baca 100644 --- a/t/discovery/reset-healthchecker.t +++ b/t/discovery/reset-healthchecker.t @@ -167,3 +167,57 @@ GET /t --- no_error_log unhealthy TCP increment (10/30) --- error_code: 503 + + + +=== TEST 3: Validate healthchecker deletion on node count returned is nil +--- http_config +server { + listen 3000 ; + location / { + return 200 'ok'; + } +} +--- apisix_yaml +routes: + - + uris: + - / + upstream_id: 1 +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local discovery = require("apisix.discovery.init").discovery + discovery.mock = { + nodes = function() + return { + {host = "127.0.0.1", port = 3000, weight = 50}, + {host = "127.0.0.1", port = 8000, weight = 50}, + } + end + } + local http = require "resty.http" + local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/" + local httpc = http.new() + local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false}) + ngx.sleep(5) + discovery.mock = { + nodes = function() + return nil + end + } + local http = require "resty.http" + local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/" + local httpc = http.new() + local res, err = httpc:request_uri(uri, {method = "GET", keepalive = false}) + ngx.status = res.status + ngx.sleep(5) + } + } +--- request +GET /t +--- timeout: 22 +--- no_error_log +unhealthy TCP increment (10/30) +--- error_code: 503