Skip to content

bug: when a domain name exists in the upstream node configuration, roundrobin is abnormal #4047

Description

@Firstsawyou

Issue description

When configuring upstream, "upstream.type" is "roundrobin". When there is a domain name in the upstream node (ip and domain name are mixed use/all are configuration domain names), then only the node with the largest weight value will be hit. When there are multiple maximum weight nodes, multiple nodes will be accessed in roundrobin mode.

Environment

  • apisix version (cmd: apisix version): 2.5
  • OS (cmd: uname -a): Linux
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): nginx version: openresty/1.19.3.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API): 3.4.0
  • apisix-dashboard version, if have:

Minimal test code / Steps to reproduce the issue

After the request is successful, the upstream will return the corresponding port number.

  1. Create a route, all nodes are domain names, and the value of weight is the same.
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uris":[
        "/get"
    ],
    "name":"up-test-01",
    "upstream":{
        "nodes":[
            {
                "host":"localhost.localdomain",
                "port":1981,
                "weight":1
            },
            {
                "host":"localhost",
                "port":1982,
                "weight":1
            }
        ],
        "type":"roundrobin",
        "pass_host":"pass"
    },
    "status":1
}'

Test:

$ for i in `seq 1 10`; do curl http://127.0.0.1:9080/get; done
1981
1981
1981
1982
1981
1982
1981
1982
1982
1982
  1. Create a route, all nodes are domain names, and the localhost.localdomain domain name node has the largest weight.
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uris":[
        "/get"
    ],
    "name":"up-test-01",
    "upstream":{
        "nodes":[
            {
                "host":"localhost.localdomain",
                "port":1981,
                "weight":4
            },
            {
                "host":"localhost",
                "port":1982,
                "weight":1
            }
        ],
        "type":"roundrobin",
        "pass_host":"pass"
    },
    "status":1
}'

Test:

$ for i in `seq 1 10`; do curl http://127.0.0.1:9080/get; done
1981
1981
1981
1981
1981
1981
1981
1981
1981
1981
  1. Create a route, mix ip and domain name, and localhost.localdomain domain name node has the largest weight.
curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uris":[
        "/get"
    ],
    "name":"up-test-01",
    "upstream":{
        "nodes":[
            {
                "host":"127.0.0.1",
                "port":1980,
                "weight":1
            },
            {
                "host":"127.0.0.1",
                "port":1981,
                "weight":1
            },
            {
                "host":"localhost",
                "port":1982,
                "weight":4
            }
        ],
        "type":"roundrobin",
        "pass_host":"pass"
    },
    "status":1
}'

Test:

$ for i in `seq 1 10`; do curl http://127.0.0.1:9080/get; done
1982
1982
1982
1982
1982
1982
1982
1982
1982
1982

What's the expected result?

When there is a domain name configuration in upstream and the domain name node has the maximum weight value, it should be able to roundrobin all nodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions