You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/08/18 08:50:21 UTC

[apisix] branch release/2.13 updated: fix: the phases after proxy should run when 500 happens before proxy

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

spacewander pushed a commit to branch release/2.13
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/release/2.13 by this push:
     new 8c4796416 fix: the phases after proxy should run when 500 happens before proxy
8c4796416 is described below

commit 8c479641662da528b009abf0afa1c558df60ba7f
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Thu Aug 18 16:50:12 2022 +0800

    fix: the phases after proxy should run when 500 happens before proxy
---
 apisix/init.lua           |  8 +++----
 t/APISIX.pm               |  1 +
 t/error_page/error_page.t | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 3586fea28..532f53a79 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -447,6 +447,10 @@ function _M.http_access_phase()
     api_ctx.route_id = route.value.id
     api_ctx.route_name = route.value.name
 
+    local ref = ctxdump.stash_ngx_ctx()
+    core.log.info("stash ngx ctx: ", ref)
+    ngx_var.ctx_ref = ref
+
     -- run global rule
     plugin.run_global_rules(api_ctx, router.global_rules, nil)
 
@@ -544,10 +548,6 @@ function _M.http_access_phase()
     -- run the before_proxy method in access phase first to avoid always reinit request
     common_phase("before_proxy")
 
-    local ref = ctxdump.stash_ngx_ctx()
-    core.log.info("stash ngx ctx: ", ref)
-    ngx_var.ctx_ref = ref
-
     local up_scheme = api_ctx.upstream_scheme
     if up_scheme == "grpcs" or up_scheme == "grpc" then
         return ngx.exec("@grpc_pass")
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 859ae21da..72bc093b5 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -587,6 +587,7 @@ _EOC_
             more_clear_headers Date;
         }
 
+        # this configuration is needed as error_page is configured in http block
         location \@50x.html {
             set \$from_error_page 'true';
             content_by_lua_block {
diff --git a/t/error_page/error_page.t b/t/error_page/error_page.t
index 70cc34c68..981dc36a1 100644
--- a/t/error_page/error_page.t
+++ b/t/error_page/error_page.t
@@ -198,3 +198,58 @@ qr/(stash|fetch) ngx ctx/
 --- grep_error_log_out
 stash ngx ctx
 fetch ngx ctx
+
+
+
+=== TEST 11: check if the phases after proxy are run when 500 happens before proxy
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "serverless-post-function": {
+                            "functions" : ["return function() if ngx.var.http_x_test_status ~= nil then;ngx.exit(tonumber(ngx.var.http_x_test_status));end;end"]
+                        },
+                        "serverless-pre-function": {
+                            "phase": "log",
+                            "functions" : ["return function() ngx.log(ngx.WARN, 'run log phase in error_page') end"]
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/*"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 12: hit
+--- request
+GET /hello
+--- more_headers
+X-Test-Status: 500
+--- error_code: 500
+--- response_body_like
+.*apisix.apache.org.*
+--- error_log
+run log phase in error_page