Baoyuantop commented on code in PR #13894:
URL: https://github.com/apache/apisix/pull/13894#discussion_r4284563339


##########
apisix/healthcheck_manager.lua:
##########
@@ -250,12 +251,46 @@ function _M.fetch_checker(resource_path, resource_ver)
 end
 
 
+-- resty.healthcheck INTERNAL_STATES: 1=healthy, 2=unhealthy,
+-- 3=mostly_healthy, 4=mostly_unhealthy. Routing treats 1 and 3 as usable.
+local SHM_HEALTHY = {
+    [1] = true,
+    [3] = true,
+}
+
+
+-- SHM is the cross-worker source of truth. get_target_status reads a
+-- worker-local cache filled asynchronously via resty.events, so a worker
+-- that missed the event (or whose checker was created after another worker
+-- already flipped the node) keeps routing to an unhealthy node
+-- (apache/apisix#13888).
+local function fetch_shm_target_status(checker, ip, port, hostname)
+    local shm = checker.shm
+    local prefix = checker.TARGET_STATE
+    if not shm or not prefix or not ip or not port then
+        return nil
+    end
+    hostname = hostname or ip
+    local key = prefix .. ":" .. ip .. ":" .. tostring(port) .. ":" .. hostname
+    local state = shm:get(key)
+    if state == nil then
+        return nil
+    end
+    return SHM_HEALTHY[state] == true
+end
+
+
 function _M.fetch_node_status(checker, ip, port, hostname)
     -- check if the checker is valid
     if not checker or checker.dead then
         return true
     end
 
+    local shm_ok = fetch_shm_target_status(checker, ip, port, hostname)
+    if shm_ok ~= nil then
+        return shm_ok

Review Comment:
   AI instance picker ignores shared health flips. When shm alone marks an AI 
instance unhealthy, fetch_node_status sees the flip but the plugin keeps its 
cached picker. Its picker version and health version use only 
checker.status_ver, so requests keep reaching that instance.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to