Skip to content

Commit 174044e

Browse files
committed
fix(ext-plugin): should use separate tokens for {pre,post}-req
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
1 parent f54784b commit 174044e

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

apisix/plugins/ext-plugin-post-req.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ local core = require("apisix.core")
1818
local ext = require("apisix.plugins.ext-plugin.init")
1919

2020

21+
local name = "ext-plugin-post-req"
2122
local _M = {
2223
version = 0.1,
2324
priority = -3000,
24-
name = "ext-plugin-post-req",
25+
name = name,
2526
schema = ext.schema,
2627
}
2728

@@ -32,7 +33,7 @@ end
3233

3334

3435
function _M.access(conf, ctx)
35-
return ext.communicate(conf, ctx)
36+
return ext.communicate(conf, ctx, name)
3637
end
3738

3839

apisix/plugins/ext-plugin-pre-req.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ local core = require("apisix.core")
1818
local ext = require("apisix.plugins.ext-plugin.init")
1919

2020

21+
local name = "ext-plugin-pre-req"
2122
local _M = {
2223
version = 0.1,
2324
priority = 12000,
24-
name = "ext-plugin-pre-req",
25+
name = name,
2526
schema = ext.schema,
2627
}
2728

@@ -32,7 +33,7 @@ end
3233

3334

3435
function _M.rewrite(conf, ctx)
35-
return ext.communicate(conf, ctx)
36+
return ext.communicate(conf, ctx, name)
3637
end
3738

3839

apisix/plugins/ext-plugin/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ local rpc_handlers = {
305305
core.log.notice("get conf token: ", token, " conf: ", core.json.delay_encode(conf.conf))
306306
return token
307307
end,
308-
function (conf, ctx, sock)
309-
local token, err = core.lrucache.plugin_ctx(lrucache, ctx, nil, rpc_call,
308+
function (conf, ctx, sock, entry)
309+
local token, err = core.lrucache.plugin_ctx(lrucache, ctx, entry, rpc_call,
310310
constants.RPC_PREPARE_CONF, conf, ctx)
311311
if not token then
312312
return nil, err
@@ -498,7 +498,7 @@ local rpc_handlers = {
498498
}
499499

500500

501-
rpc_call = function (ty, conf, ctx)
501+
rpc_call = function (ty, conf, ctx, ...)
502502
local path = helper.get_path()
503503

504504
local sock = socket_tcp()
@@ -508,7 +508,7 @@ rpc_call = function (ty, conf, ctx)
508508
return nil, "failed to connect to the unix socket " .. path .. ": " .. err
509509
end
510510

511-
local res, err, code, body = rpc_handlers[ty + 1](conf, ctx, sock)
511+
local res, err, code, body = rpc_handlers[ty + 1](conf, ctx, sock, ...)
512512
if not res then
513513
sock:close()
514514
return nil, err
@@ -535,12 +535,12 @@ local function create_lrucache()
535535
end
536536

537537

538-
function _M.communicate(conf, ctx)
538+
function _M.communicate(conf, ctx, plugin_name)
539539
local ok, err, code, body
540540
local tries = 0
541541
while tries < 3 do
542542
tries = tries + 1
543-
ok, err, code, body = rpc_call(constants.RPC_HTTP_REQ_CALL, conf, ctx)
543+
ok, err, code, body = rpc_call(constants.RPC_HTTP_REQ_CALL, conf, ctx, plugin_name)
544544
if ok then
545545
if code then
546546
return code, body

t/plugin/ext-plugin/sanity.t

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ __DATA__
8181
[[{
8282
"uri": "/hello",
8383
"plugins": {
84-
"ext-plugin-pre-req": {},
85-
"ext-plugin-post-req": {}
84+
"ext-plugin-pre-req": {"a":"b"},
85+
"ext-plugin-post-req": {"c":"d"}
8686
},
8787
"upstream": {
8888
"nodes": {
@@ -128,6 +128,10 @@ sending rpc type: 2 data length:
128128
receiving rpc type: 2 data length:
129129
sending rpc type: 2 data length:
130130
receiving rpc type: 2 data length:
131+
sending rpc type: 1 data length:
132+
receiving rpc type: 1 data length:
133+
sending rpc type: 1 data length:
134+
receiving rpc type: 1 data length:
131135
sending rpc type: 2 data length:
132136
receiving rpc type: 2 data length:
133137
sending rpc type: 2 data length:
@@ -256,6 +260,14 @@ sending rpc type: 1 data length:
256260
receiving rpc type: 1 data length:
257261
sending rpc type: 1 data length:
258262
receiving rpc type: 1 data length:
263+
sending rpc type: 1 data length:
264+
receiving rpc type: 1 data length:
265+
sending rpc type: 1 data length:
266+
receiving rpc type: 1 data length:
267+
sending rpc type: 1 data length:
268+
receiving rpc type: 1 data length:
269+
sending rpc type: 1 data length:
270+
receiving rpc type: 1 data length:
259271
--- error_log
260272
flush conf token lrucache
261273
--- no_error_log

0 commit comments

Comments
 (0)