-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fix lua-nginx-module context was cleared when ngx.send_hea…
…der() trigger filter_finalize case (#13316) backport patch in openresty/lua-nginx-module#2323 Context: openresty/lua-nginx-module#2320 FTI-6005
- Loading branch information
Showing
4 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
build/openresty/patches/nginx-1.25.3_07-fix-lua-context-clean-by-send-header.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
diff --git a/bundle/ngx_lua-0.10.26/src/ngx_http_lua_util.c b/bundle/ngx_lua-0.10.26/src/ngx_http_lua_util.c | ||
index 8fd2656..b2fdb6c 100644 | ||
--- a/bundle/ngx_lua-0.10.26/src/ngx_http_lua_util.c | ||
+++ b/bundle/ngx_lua-0.10.26/src/ngx_http_lua_util.c | ||
@@ -549,6 +549,10 @@ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r, | ||
if (!ctx->buffering) { | ||
dd("sending headers"); | ||
rc = ngx_http_send_header(r); | ||
+ if (r->filter_finalize) { | ||
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module); | ||
+ } | ||
+ | ||
ctx->header_sent = 1; | ||
return rc; | ||
} | ||
diff --git a/bundle/ngx_lua-0.10.26/t/002-content.t b/bundle/ngx_lua-0.10.26/t/002-content.t | ||
index 54de40e..eb9d587 100644 | ||
--- a/bundle/ngx_lua-0.10.26/t/002-content.t | ||
+++ b/bundle/ngx_lua-0.10.26/t/002-content.t | ||
@@ -1098,3 +1098,25 @@ failed to load inlined Lua code: content_by_lua(...45678901234567890123456789012 | ||
GET /lua | ||
--- response_body_like: 503 Service Temporarily Unavailable | ||
--- error_code: 503 | ||
+ | ||
+ | ||
+ | ||
+=== TEST 52: send_header trigger filter finalize does not clear the ctx | ||
+--- config | ||
+ location /lua { | ||
+ content_by_lua_block { | ||
+ ngx.header["Last-Modified"] = ngx.http_time(ngx.time()) | ||
+ ngx.send_headers() | ||
+ local phase = ngx.get_phase() | ||
+ } | ||
+ header_filter_by_lua_block { | ||
+ ngx.header["X-Hello-World"] = "Hello World" | ||
+ } | ||
+ } | ||
+--- request | ||
+GET /lua | ||
+--- more_headers | ||
+If-Unmodified-Since: Wed, 01 Jan 2020 07:28:00 GMT | ||
+--- error_code: 412 | ||
+--- no_error_log | ||
+unknown phase: 0 |
3 changes: 3 additions & 0 deletions
3
changelog/unreleased/kong/fix-filter-finalize-in-send-header-clear-context.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
message: Fixed an issue where `lua-nginx-module` context was cleared when `ngx.send_header()` triggered `filter_finalize` [openresty/lua-nginx-module#2323](https://github.com/openresty/lua-nginx-module/pull/2323). | ||
type: bugfix | ||
scope: Core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use Test::Nginx::Socket::Lua; | ||
|
||
#worker_connections(1014); | ||
#master_on(); | ||
#workers(2); | ||
#log_level('warn'); | ||
|
||
repeat_each(2); | ||
#repeat_each(1); | ||
|
||
plan tests => repeat_each() * (blocks() * 2); | ||
|
||
#no_diff(); | ||
#no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: send_header trigger filter finalize does not clear the ctx | ||
--- config | ||
location /lua { | ||
content_by_lua_block { | ||
ngx.header["Last-Modified"] = ngx.http_time(ngx.time()) | ||
ngx.send_headers() | ||
local phase = ngx.get_phase() | ||
} | ||
header_filter_by_lua_block { | ||
ngx.header["X-Hello-World"] = "Hello World" | ||
} | ||
} | ||
--- request | ||
GET /lua | ||
--- more_headers | ||
If-Unmodified-Since: Wed, 01 Jan 2020 07:28:00 GMT | ||
--- error_code: 412 | ||
--- no_error_log | ||
unknown phase: 0 |
fb63631
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:fb6363188246c866cecf72889053c4ba8a455fef
Artifacts available https://github.com/Kong/kong/actions/runs/9934725114