Skip to content

Commit

Permalink
bugfix: check the count of upstream valid node. (apache#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis authored and SaberMaster committed Jun 30, 2020
1 parent 1b4dec0 commit 8bb9bfa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
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

0 comments on commit 8bb9bfa

Please sign in to comment.