This is an automated email from the ASF dual-hosted git repository. membphis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push: new 60b8853 bugfix: check the count of upstream valid node. (#1292) 60b8853 is described below commit 60b88536fe774ceb6af820b75a4a5cd4428a4d4f Author: YuanSheng Wang <membp...@gmail.com> AuthorDate: Thu Mar 19 12:07:43 2020 +0800 bugfix: check the count of upstream valid node. (#1292) --- lua/apisix/balancer.lua | 4 ++++ t/node/upstream-domain.t | 60 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/lua/apisix/balancer.lua b/lua/apisix/balancer.lua index 400aff5..c2b94cd 100644 --- a/lua/apisix/balancer.lua +++ b/lua/apisix/balancer.lua @@ -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 diff --git a/t/node/upstream-domain.t b/t/node/upstream-domain.t index 426dc87..99f30fa 100644 --- a/t/node/upstream-domain.t +++ b/t/node/upstream-domain.t @@ -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 { @@ -137,7 +193,7 @@ passed -=== TEST 6: delete upstream +=== TEST 8: delete upstream --- config location /t { content_by_lua_block {