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

bugfix: check the count of upstream valid node. #1292

Merged
merged 2 commits into from
Mar 19, 2020
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
4 changes: 4 additions & 0 deletions lua/apisix/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ local function pick_server(route, ctx)
key = up_conf.type .. "#route_" .. route.value.id
end

if core.table.nkeys(up_conf.nodes) == 0 then
return nil, nil, "no valid upstream node"
end

local checker = fetch_healthchecker(up_conf, healthcheck_parent, version)

ctx.balancer_try_count = (ctx.balancer_try_count or 0) + 1
Expand Down
60 changes: 58 additions & 2 deletions t/node/upstream-domain.t
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,63 @@ qr/dns resolver domain: baidu.com to \d+.\d+.\d+.\d+/



=== TEST 5: delete route
=== TEST 5: set upstream(invalid node host)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/upstreams/1',
ngx.HTTP_PUT,
[[{
"nodes": {
"httpbin.orgx:80": 0
},
"type": "roundrobin",
"desc": "new upstream"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 6:
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local function test()
local code, body = t('/hello', ngx.HTTP_GET)

ngx.say("status: ", code)
end
test()
test()
}
}
--- request
GET /t
--- response_body
status: 500
status: 500
--- error_log
failed to parse domain in upstream: server returned error code
failed to parse domain in upstream: server returned error code



=== TEST 7: delete route
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -137,7 +193,7 @@ passed



=== TEST 6: delete upstream
=== TEST 8: delete upstream
--- config
location /t {
content_by_lua_block {
Expand Down