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 54abe58  bugfix: failed to set server peer when upstreams.node is 
address in apisix.yaml (#1824)
54abe58 is described below

commit 54abe58315c1143cf1cfb23c7c93b26321b6a11e
Author: wrl96 <393073...@qq.com>
AuthorDate: Fri Jul 10 18:47:11 2020 +0800

    bugfix: failed to set server peer when upstreams.node is address in 
apisix.yaml (#1824)
    
    Fix #1798
---
 apisix/core/config_yaml.lua           |  2 +-
 apisix/init.lua                       | 11 ++++++++---
 t/config-center-yaml/route-upstream.t | 22 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/apisix/core/config_yaml.lua b/apisix/core/config_yaml.lua
index eed861f..bb1cd25 100644
--- a/apisix/core/config_yaml.lua
+++ b/apisix/core/config_yaml.lua
@@ -311,7 +311,7 @@ end
 
 
 function _M.fetch_created_obj(key)
-    return created_obj[key]
+    return created_obj[sub_str(key, 2)]
 end
 
 
diff --git a/apisix/init.lua b/apisix/init.lua
index 41295f0..782ebf2 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -313,9 +313,14 @@ function _M.http_access_phase()
     local enable_websocket
     local up_id = route.value.upstream_id
     if up_id then
-        local upstreams_etcd = core.config.fetch_created_obj("/upstreams")
-        if upstreams_etcd then
-            local upstream = upstreams_etcd:get(tostring(up_id))
+        local upstreams = core.config.fetch_created_obj("/upstreams")
+        if upstreams then
+            local upstream = upstreams:get(tostring(up_id))
+            if not upstream then
+                core.log.error("failed to find upstream by id: " .. up_id)
+                return core.response.exit(500)
+            end
+
             if upstream.has_domain then
                 local _, err = parsed_domain(upstream, api_ctx.conf_version,
                                              parse_domain_in_up, upstream)
diff --git a/t/config-center-yaml/route-upstream.t 
b/t/config-center-yaml/route-upstream.t
index d8d44a7..51fddcb 100644
--- a/t/config-center-yaml/route-upstream.t
+++ b/t/config-center-yaml/route-upstream.t
@@ -139,3 +139,25 @@ GET /hello
 hello world
 --- no_error_log
 [error]
+
+
+
+=== TEST 5: upstream domain
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+    -
+        uri: /get
+        upstream_id: 1
+upstreams:
+    -
+        id: 1
+        nodes:
+            "httpbin.org:80": 1
+        type: roundrobin
+#END
+--- request
+GET /get
+--- error_code: 200
+--- no_error_log
+[error]

Reply via email to