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 ef1970a1f fix: replace module-level mutable tables with per-call
allocation (#13369)
ef1970a1f is described below
commit ef1970a1fb55a2e8c20d9c7a0d418ffd9d5e101f
Author: Nic <[email protected]>
AuthorDate: Thu May 14 17:29:25 2026 +0800
fix: replace module-level mutable tables with per-call allocation (#13369)
---
apisix/api_router.lua | 4 ++--
apisix/control/router.lua | 7 ++++---
apisix/plugins/proxy-cache/util.lua | 7 ++++---
apisix/plugins/redirect.lua | 7 ++++---
apisix/stream/router/ip_port.lua | 5 ++---
5 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/apisix/api_router.lua b/apisix/api_router.lua
index 9fbf328bf..92b210d3e 100644
--- a/apisix/api_router.lua
+++ b/apisix/api_router.lua
@@ -24,7 +24,6 @@ local type = type
local _M = {}
-local match_opts = {}
local has_route_not_under_apisix
@@ -105,10 +104,11 @@ function _M.match(api_ctx)
return false
end
- core.table.clear(match_opts)
+ local match_opts = core.tablepool.fetch("api_router_match_opts", 0, 4)
match_opts.method = api_ctx.var.request_method
local ok = api_router:dispatch(api_ctx.var.uri, match_opts, api_ctx)
+ core.tablepool.release("api_router_match_opts", match_opts)
return ok
end
diff --git a/apisix/control/router.lua b/apisix/control/router.lua
index e6e5ff9b3..e5044bf54 100644
--- a/apisix/control/router.lua
+++ b/apisix/control/router.lua
@@ -174,7 +174,6 @@ end -- do
do
- local match_opts = {}
local cached_version
local router
@@ -190,10 +189,12 @@ function _M.match(uri)
cached_version = plugin_mod.load_times
end
- core.table.clear(match_opts)
+ local match_opts = core.tablepool.fetch("control_router_match_opts", 0, 4)
match_opts.method = get_method()
- return router:dispatch(uri, match_opts)
+ local ok, err = router:dispatch(uri, match_opts)
+ core.tablepool.release("control_router_match_opts", match_opts)
+ return ok, err
end
end -- do
diff --git a/apisix/plugins/proxy-cache/util.lua
b/apisix/plugins/proxy-cache/util.lua
index 26c6e814b..4e7266323 100644
--- a/apisix/plugins/proxy-cache/util.lua
+++ b/apisix/plugins/proxy-cache/util.lua
@@ -28,9 +28,8 @@ local tonumber = tonumber
local _M = {}
-local tmp = {}
function _M.generate_complex_value(data, ctx)
- core.table.clear(tmp)
+ local tmp = core.tablepool.fetch("proxy_cache_complex_value", #data, 0)
core.log.info("proxy-cache complex value: ", core.json.delay_encode(data))
for i, value in ipairs(data) do
@@ -43,7 +42,9 @@ function _M.generate_complex_value(data, ctx)
end
end
- return tab_concat(tmp, "")
+ local result = tab_concat(tmp, "")
+ core.tablepool.release("proxy_cache_complex_value", tmp)
+ return result
end
diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua
index da81859c3..b07754a17 100644
--- a/apisix/plugins/redirect.lua
+++ b/apisix/plugins/redirect.lua
@@ -131,14 +131,13 @@ function _M.check_schema(conf)
end
- local tmp = {}
local function concat_new_uri(uri, ctx)
local passed_uri_segs, err = lrucache(uri, nil, parse_uri, uri)
if not passed_uri_segs then
return nil, err
end
- core.table.clear(tmp)
+ local tmp = core.tablepool.fetch("redirect_new_uri", #passed_uri_segs, 0)
for _, uri_segs in ipairs(passed_uri_segs) do
local pat1 = uri_segs[1] -- \$host
@@ -154,7 +153,9 @@ local function concat_new_uri(uri, ctx)
end
end
- return tab_concat(tmp, "")
+ local result = tab_concat(tmp, "")
+ core.tablepool.release("redirect_new_uri", tmp)
+ return result
end
local function get_port(attr)
diff --git a/apisix/stream/router/ip_port.lua b/apisix/stream/router/ip_port.lua
index 3b89b59a2..45e8e5531 100644
--- a/apisix/stream/router/ip_port.lua
+++ b/apisix/stream/router/ip_port.lua
@@ -144,8 +144,6 @@ end
do
- local match_opts = {}
-
function _M.match(api_ctx)
-- Rebuild the router when stream_routes change OR when services
change,
-- so updates to a referenced service (status, deletion, late sync from
@@ -166,10 +164,11 @@ do
if sni and tls_router then
local sni_rev = sni:reverse()
- core.table.clear(match_opts)
+ local match_opts =
core.tablepool.fetch("stream_router_match_opts", 0, 4)
match_opts.vars = api_ctx.var
local _, err = tls_router:dispatch(sni_rev, match_opts, api_ctx)
+ core.tablepool.release("stream_router_match_opts", match_opts)
if err then
return false, "failed to match TLS router: " .. err
end