This is an automated email from the ASF dual-hosted git repository.

nic-6443 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new a76f9c43a fix(workflow): tolerate missing _workflow_cache in log phase 
(#13512)
a76f9c43a is described below

commit a76f9c43ace8d857feb3c35e1e0eb8155191a321
Author: Nic <[email protected]>
AuthorDate: Fri Jun 12 10:51:17 2026 +0800

    fix(workflow): tolerate missing _workflow_cache in log phase (#13512)
---
 apisix/plugins/workflow.lua |   8 ++++
 t/plugin/workflow3.t        | 104 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+)

diff --git a/apisix/plugins/workflow.lua b/apisix/plugins/workflow.lua
index 3b68c3d09..c3aa78e0a 100644
--- a/apisix/plugins/workflow.lua
+++ b/apisix/plugins/workflow.lua
@@ -178,6 +178,14 @@ function _M.access(conf, ctx)
 end
 
 function _M.log(conf, ctx)
+    -- ctx._workflow_cache is created in the access phase, but the access
+    -- phase may be skipped, e.g. when a plugin of the route finishes the
+    -- request in the rewrite phase while the workflow plugin is configured
+    -- in a global rule
+    if not ctx._workflow_cache then
+        return
+    end
+
     for idx, rule in ipairs(conf.rules) do
         local match_result = ctx._workflow_cache[idx]
         if match_result then
diff --git a/t/plugin/workflow3.t b/t/plugin/workflow3.t
index 5a2e6fa62..70a0aca71 100644
--- a/t/plugin/workflow3.t
+++ b/t/plugin/workflow3.t
@@ -142,3 +142,107 @@ GET /test_concurrency
 503
 503
 503
+
+
+
+=== TEST 3: set up workflow with limit-conn in global rule, and a route with 
cors
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/global_rules/1',
+                 ngx.HTTP_PUT,
+                 json.encode({
+                    plugins = {
+                        workflow = {
+                            rules = {
+                                {
+                                    case = {
+                                        {"uri", "==", "/hello"}
+                                    },
+                                    actions = {
+                                        {
+                                            "limit-conn",
+                                            {
+                                                conn = 2,
+                                                burst = 1,
+                                                default_conn_delay = 0.1,
+                                                rejected_code = 503,
+                                                key = "remote_addr"
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                 })
+            )
+
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 json.encode({
+                    uri = "/hello",
+                    plugins = {
+                        cors = {}
+                    },
+                    upstream = {
+                        nodes = {
+                            ["127.0.0.1:1980"] = 1
+                        },
+                        type = "roundrobin"
+                    }
+                 })
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 4: OPTIONS preflight finished by cors in rewrite phase, workflow log 
phase should not fail
+--- request
+OPTIONS /hello
+--- more_headers
+Origin: https://sub.domain.com
+Access-Control-Request-Method: GET
+--- error_code: 200
+--- no_error_log
+_workflow_cache
+
+
+
+=== TEST 5: clean up
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/global_rules/1', 
ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE)
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed

Reply via email to