Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Firstsawyou opened this issue Apr 14, 2021 · 3 comments · Fixed by #4061
Closed
Labels
bug Something isn't working

Comments

@Firstsawyou
Copy link
Contributor

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.

@Firstsawyou
Copy link
Contributor Author

@spacewander @membphis Please take a look.

@membphis membphis added the bug Something isn't working label Apr 14, 2021
@membphis
Copy link
Member

nice job @Firstsawyou

we need to fix this bug ^_^

@Firstsawyou
Copy link
Contributor Author

nice job @Firstsawyou

we need to fix this bug ^_^

Got it.

spacewander added a commit to spacewander/incubator-apisix that referenced this issue Apr 15, 2021
Fix apache#4047

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
spacewander added a commit to spacewander/incubator-apisix that referenced this issue Apr 15, 2021
Fix apache#4047

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
spacewander added a commit that referenced this issue Apr 16, 2021
Fix #4047

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants