Skip to content

Commit 4e05192

Browse files
authored
fix: health checker can't be released due to health parent being released early (#11760)
1 parent a6412d2 commit 4e05192

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

apisix/core/config_util.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ end
5858
-- or cancelled. Note that Nginx worker exit doesn't trigger the clean handler.
5959
-- Return an index so that we can cancel it later.
6060
function _M.add_clean_handler(item, func)
61+
if not item.clean_handlers then
62+
return nil, "clean handlers for the item are nil"
63+
end
64+
6165
if not item.clean_handlers._id then
6266
item.clean_handlers._id = 1
6367
end

apisix/upstream.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ local function create_checker(upstream)
155155
end
156156
end
157157

158+
local check_idx, err = core.config_util.add_clean_handler(healthcheck_parent, release_checker)
159+
if not check_idx then
160+
upstream.is_creating_checker = nil
161+
checker:clear()
162+
checker:stop()
163+
core.log.error("failed to add clean handler, err:",
164+
err, " healthcheck parent:", core.json.delay_encode(healthcheck_parent, true))
165+
166+
return nil
167+
end
168+
158169
healthcheck_parent.checker = checker
159170
healthcheck_parent.checker_upstream = upstream
160-
healthcheck_parent.checker_idx =
161-
core.config_util.add_clean_handler(healthcheck_parent, release_checker)
171+
healthcheck_parent.checker_idx = check_idx
162172

163173
upstream.is_creating_checker = nil
164174

0 commit comments

Comments
 (0)