Skip to content

fix: release checker when nodes are nil #12149

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions apisix/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 54 additions & 0 deletions t/discovery/reset-healthchecker.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading