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 81dbc5b75 fix: preserve stream service plugin context (#13402)
81dbc5b75 is described below
commit 81dbc5b755a2d66fe15c05b723a4d2a2da18f8dd
Author: Nic <[email protected]>
AuthorDate: Thu May 21 16:17:03 2026 +0800
fix: preserve stream service plugin context (#13402)
---
apisix/init.lua | 8 +--
t/stream-plugin/syslog.t | 136 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 139 insertions(+), 5 deletions(-)
diff --git a/apisix/init.lua b/apisix/init.lua
index cc83c49cf..a229fe857 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -1352,9 +1352,11 @@ function _M.stream_preread_phase()
api_ctx.plugins = plugin.stream_filter(matched_route, plugins)
-- core.log.info("valid plugins: ", core.json.delay_encode(plugins, true))
- api_ctx.conf_type = "stream/route"
- api_ctx.conf_version = matched_route.modifiedIndex
- api_ctx.conf_id = matched_route.value.id
+ if not api_ctx.conf_type then
+ api_ctx.conf_type = "stream/route"
+ api_ctx.conf_version = matched_route.modifiedIndex
+ api_ctx.conf_id = matched_route.value.id
+ end
api_ctx.route_id = matched_route.value.id
api_ctx.route_name = matched_route.value.name
diff --git a/t/stream-plugin/syslog.t b/t/stream-plugin/syslog.t
index 030b53dc5..d2c48019c 100644
--- a/t/stream-plugin/syslog.t
+++ b/t/stream-plugin/syslog.t
@@ -349,7 +349,139 @@ sending a batch logs to 127.0.0.1:5045
-=== TEST 8: log format in plugin
+=== TEST 8: check service plugin configuration updating
+--- stream_conf_enable
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local function request_stream()
+ local sock = ngx.socket.tcp()
+ local ok, err = sock:connect("127.0.0.1", 1985)
+ if not ok then
+ ngx.status = 500
+ ngx.say("failed to connect: ", err)
+ return nil
+ end
+
+ local ok, err = sock:send("mmm")
+ if not ok then
+ sock:close()
+ ngx.status = 500
+ ngx.say("failed to send: ", err)
+ return nil
+ end
+
+ local body, err = sock:receive("*a")
+ sock:close()
+ if not body then
+ ngx.status = 500
+ ngx.say("failed to receive: ", err)
+ return nil
+ end
+
+ return body
+ end
+
+ local code, body1 = t('/apisix/admin/services/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "syslog": {
+ "host" : "127.0.0.1",
+ "port" : 5044,
+ "batch_max_size": 1
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1995": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say("fail")
+ return
+ end
+
+ local code, body2 = t('/apisix/admin/stream_routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "service_id": "1"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say("fail")
+ return
+ end
+
+ ngx.sleep(0.5)
+
+ local body3 = request_stream()
+ if not body3 then
+ return
+ end
+
+ local code, body4 = t('/apisix/admin/services/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "syslog": {
+ "host" : "127.0.0.1",
+ "port" : 5045,
+ "batch_max_size": 1
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1995": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say("fail")
+ return
+ end
+
+ ngx.sleep(0.5)
+
+ local body5 = request_stream()
+ if not body5 then
+ return
+ end
+
+ ngx.print(body1)
+ ngx.print(body2)
+ ngx.print(body3)
+ ngx.print(body4)
+ ngx.print(body5)
+ }
+ }
+--- request
+GET /t
+--- wait: 0.5
+--- response_body
+passedpassedhello world
+passedhello world
+--- grep_error_log eval
+qr/sending a batch logs to 127.0.0.1:(\d+)/
+--- grep_error_log_out
+sending a batch logs to 127.0.0.1:5044
+sending a batch logs to 127.0.0.1:5045
+
+
+
+=== TEST 9: log format in plugin
--- config
location /t {
content_by_lua_block {
@@ -393,7 +525,7 @@ passed
-=== TEST 9: access
+=== TEST 10: access
--- stream_extra_init_by_lua
local syslog = require("apisix.plugins.syslog.init")
local json = require("apisix.core.json")