This is an automated email from the ASF dual-hosted git repository.
wenming 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 70d3f0b bug: fixed bug when no valid upstream node. (#893)
70d3f0b is described below
commit 70d3f0b608b178798e846c1fab867566720e0df0
Author: YuanSheng Wang <[email protected]>
AuthorDate: Mon Nov 25 16:46:20 2019 +0800
bug: fixed bug when no valid upstream node. (#893)
---
lua/apisix/balancer.lua | 3 ++-
t/node/chash-balance.t | 70 ++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 68 insertions(+), 5 deletions(-)
diff --git a/lua/apisix/balancer.lua b/lua/apisix/balancer.lua
index 01cb0f5..6d37426 100644
--- a/lua/apisix/balancer.lua
+++ b/lua/apisix/balancer.lua
@@ -240,7 +240,8 @@ local function pick_server(route, ctx)
local server, err = server_picker.get(ctx)
if not server then
- return nil, nil, "failed to find valid upstream server" .. err
+ err = err or "no valid upstream node"
+ return nil, nil, "failed to find valid upstream server, " .. err
end
if up_conf.timeout then
diff --git a/t/node/chash-balance.t b/t/node/chash-balance.t
index 247fc37..dd24e69 100644
--- a/t/node/chash-balance.t
+++ b/t/node/chash-balance.t
@@ -321,8 +321,8 @@ passed
return
end
ports_count[res.body] = (ports_count[res.body] or 0) + 1
- end
-
+ end
+
local ports_arr = {}
for port, count in pairs(ports_count) do
table.insert(ports_arr, {port = port, count = count})
@@ -399,8 +399,8 @@ passed
return
end
ports_count[res.body] = (ports_count[res.body] or 0) + 1
- end
-
+ end
+
local ports_arr = {}
for port, count in pairs(ports_count) do
table.insert(ports_arr, {port = port, count = count})
@@ -421,3 +421,65 @@ GET /t
[{"count":5,"port":"1982"},{"count":7,"port":"1981"},{"count":6,"port":"1980"}]
--- no_error_log
[error]
+
+
+
+=== TEST 11: set route(weight 0)
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/server_port",
+ "upstream": {
+ "key": "arg_device_id",
+ "type": "chash",
+ "nodes": {
+ "127.0.0.1:1980": 0,
+ "127.0.0.1:1981": 0
+ }
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 12: hit routes
+--- config
+ location /t {
+ content_by_lua_block {
+ local http = require "resty.http"
+ local uri = "http://127.0.0.1:" .. ngx.var.server_port
+ .. "/server_port?device_id=1"
+
+ local httpc = http.new()
+ local res, err = httpc:request_uri(uri, {method = "GET"})
+ if not res then
+ ngx.say(err)
+ return
+ end
+
+ ngx.status = res.status
+ ngx.say(res.body)
+ }
+ }
+--- request
+GET /t
+--- error_code_like: ^(?:50\d)$
+--- error_log
+failed to find valid upstream server, no valid upstream node