Skip to content

bug: The logic for method fetch_full_registry in nacos.lua will break the loop if the previous get_url request failed #4949

Description

@rztao

Issue description

data, err = get_url(base_uri, instance_list_path .. service_info.service_name .. token_param .. namespace_param .. group_name_param) if err then log.error('get_url:', instance_list_path, ' err:', err) if not applications then applications = up_apps end return end

The above logic for method fetch_full_registry in nacos.lua will break the loop if the previous get_url request failed. This issue can be reproduced with a wrong route with service discovery configuration.

`

local data, err
    for _, service_info in ipairs(infos) do
        local namespace_param = get_namespace_param(service_info.namespace_id)
        local group_name_param = get_group_name_param(service_info.group_name)
        data, err = get_url(base_uri, instance_list_path .. service_info.service_name
                            .. token_param .. namespace_param .. group_name_param)
        if err then
            log.error('get_url:', instance_list_path, ' err:', err)
            if not applications then
                applications = up_apps
            end
            return
        end

        for _, host in ipairs(data.hosts) do
            local nodes = up_apps[service_info.service_name]
            if not nodes then
                nodes = {}
                up_apps[service_info.service_name] = nodes
            end
            core.table.insert(nodes, {
                host = host.ip,
                port = host.port,
                weight = host.weight or default_weight,
            })
        end
    end

Environment

  • apisix version (cmd: apisix version): 2.9
  • OS (cmd: uname -a): MacOs (same with Linux, not tested)
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): nginx version: openresty/1.19.3.2

Steps to reproduce

  1. Configure a route with a wrong service_name not registered in Nacos.
  2. The fetch data request for service_name configured in 1) failed or timeout is reached, it will break the loop,
    and the next requests to fetch data will be skipped but they are correctly configured.

Actual result

The next requests to fetch data will be skipped but they are correctly configured if the previous request not correctly configured or timeout reached.

Error log

log.error('get_url:', instance_list_path, ' err:', err)

Expected result

The next requests to fetch data will be not skipped when the previous request not correctly configured or timeout reached.

Metadata

Metadata

Assignees

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