Skip to content

bug: When using traffic-split , the key of chash is missing in the upstream of traffic-split #3858

@nanamikon

Description

@nanamikon

Issue description

Environment

  • apisix version (2.3):
  • OS (ubuntu 16):
  • OpenResty / Nginx version (1.19.3):
  • etcd version, if have (3.14):
  • apisix-dashboard version, if have:

Minimal test code / Steps to reproduce the issue

1.use traffic-split , and set the upstream as follow

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/index.html",
    "plugins": {
        "traffic-split": {
            "rules": [
                {
                    "match": [
                        {
                            "vars": [
                                ["http_release","==","new_release"]
                            ]
                        }
                    ],
                    "weighted_upstreams": [
                        {
                            "upstream": {
                                "type": "chash",
                                "key": "remote_addr",
                                "name": "upstream_A",
                                "nodes": {
                                    "127.0.0.1:1981":1
                                    "127.0.0.2:1981":1
                                }
                            }
                        }
                    ]
                }
            ]
        }
    },
    "upstream": {
            "type": "roundrobin",
            "nodes": {
                "127.0.0.1:1980": 1
            }
    }
}'

curl http://127.0.0.1:9080/index.html -H "release:new_release" -i

<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>openresty</center>
</body>
</html>

What's the actual result? (including assertion message & call stack if applicable)

Error can be found in error.log

2021/03/18 15:36:04 [error] 72662#72662: *683 failed to run balancer_by_lua*: /chash.lua:36: invalid argument, expect string value
stack traceback:
        [C]: in function 'error'
        /data/app/huya-nginx-proxy/apisix/core/ctx.lua:139: in function '__index'
        /data/app/huya-nginx-proxy/apisix/balancer/chash.lua:36: in function 'fetch_chash_hash_key'
        /data/app/huya-nginx-proxy/apisix/balancer/chash.lua:81: in function 'get'
        /data/app/huya-nginx-proxy/apisix/balancer.lua:172: in function 'pick_server'
        /data/app/huya-nginx-proxy/apisix/balancer.lua:197: in function 'load_balancer'
        /data/app/huya-nginx-proxy/apisix/init.lua:718: in function 'http_balancer_phase'

What's the expected result?

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions