You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "fightingcoding (via GitHub)" <gi...@apache.org> on 2023/06/17 17:15:12 UTC

[GitHub] [apisix] fightingcoding commented on issue #7633: bug: config_util.lua:71: attempt to call local 'f' (a nil value)

fightingcoding commented on issue #7633:
URL: https://github.com/apache/apisix/issues/7633#issuecomment-1595810509

   > Look like calling `cancel_clean_handler` to remove the clean handler in the middle (added by add_clean_handler) and then calling `cancel_clean_handler` may trigger this bug?
   > 
   > For example, we have handlers `[1, 2]`. The first call remove handler 1, then the handlers are `[2]`. Then the second call tries to remove the handler at the index 2, which is nil now.
   
   We also encountered a similar problem here, but we look at the code, the length of this clean_handlers should be 0 or 1, and there should be no case where the length is 2, but similar errors do appear during use, I would like to ask you to describe When the length of clean_handlers is 2, what happens? The corresponding calling code block is shown below, which has been marked.
   
   local function create_checker(upstream)
       if healthcheck == nil then
           healthcheck = require("resty.healthcheck")
       end
   
       local healthcheck_parent = upstream.parent
       if healthcheck_parent.checker and healthcheck_parent.checker_upstream == upstream then
           return healthcheck_parent.checker
       end
   
       local checker, err = healthcheck.new({
           name = get_healthchecker_name(healthcheck_parent),
           shm_name = "upstream-healthcheck",
           checks = upstream.checks,
       })
   
       if not checker then
           core.log.error("fail to create healthcheck instance: ", err)
           return nil
       end
   
       if healthcheck_parent.checker then
           **core.config_util.cancel_clean_handler(healthcheck_parent,
                                                 healthcheck_parent.checker_idx, true)**
       end
   
       core.log.info("create new checker: ", tostring(checker))
   
       local host = upstream.checks and upstream.checks.active and upstream.checks.active.host
       local port = upstream.checks and upstream.checks.active and upstream.checks.active.port
       for _, node in ipairs(upstream.nodes) do
           local ok, err = checker:add_target(node.host, port or node.port, host)
           if not ok then
               core.log.error("failed to add new health check target: ", node.host, ":",
                       port or node.port, " err: ", err)
           end
       end
   
       healthcheck_parent.checker = checker
       healthcheck_parent.checker_upstream = upstream
       healthcheck_parent.checker_idx =
           **core.config_util.add_clean_handler(healthcheck_parent, release_checker)**
   
       return checker
   end
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org