Skip to content

Commit

Permalink
fix(ext-plugin): should use separate tokens for {pre,post}-req
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Jun 21, 2021
1 parent f54784b commit 174044e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 3 additions & 2 deletions apisix/plugins/ext-plugin-post-req.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ local core = require("apisix.core")
local ext = require("apisix.plugins.ext-plugin.init")


local name = "ext-plugin-post-req"
local _M = {
version = 0.1,
priority = -3000,
name = "ext-plugin-post-req",
name = name,
schema = ext.schema,
}

Expand All @@ -32,7 +33,7 @@ end


function _M.access(conf, ctx)
return ext.communicate(conf, ctx)
return ext.communicate(conf, ctx, name)
end


Expand Down
5 changes: 3 additions & 2 deletions apisix/plugins/ext-plugin-pre-req.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ local core = require("apisix.core")
local ext = require("apisix.plugins.ext-plugin.init")


local name = "ext-plugin-pre-req"
local _M = {
version = 0.1,
priority = 12000,
name = "ext-plugin-pre-req",
name = name,
schema = ext.schema,
}

Expand All @@ -32,7 +33,7 @@ end


function _M.rewrite(conf, ctx)
return ext.communicate(conf, ctx)
return ext.communicate(conf, ctx, name)
end


Expand Down
12 changes: 6 additions & 6 deletions apisix/plugins/ext-plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ local rpc_handlers = {
core.log.notice("get conf token: ", token, " conf: ", core.json.delay_encode(conf.conf))
return token
end,
function (conf, ctx, sock)
local token, err = core.lrucache.plugin_ctx(lrucache, ctx, nil, rpc_call,
function (conf, ctx, sock, entry)
local token, err = core.lrucache.plugin_ctx(lrucache, ctx, entry, rpc_call,
constants.RPC_PREPARE_CONF, conf, ctx)
if not token then
return nil, err
Expand Down Expand Up @@ -498,7 +498,7 @@ local rpc_handlers = {
}


rpc_call = function (ty, conf, ctx)
rpc_call = function (ty, conf, ctx, ...)
local path = helper.get_path()

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

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


function _M.communicate(conf, ctx)
function _M.communicate(conf, ctx, plugin_name)
local ok, err, code, body
local tries = 0
while tries < 3 do
tries = tries + 1
ok, err, code, body = rpc_call(constants.RPC_HTTP_REQ_CALL, conf, ctx)
ok, err, code, body = rpc_call(constants.RPC_HTTP_REQ_CALL, conf, ctx, plugin_name)
if ok then
if code then
return code, body
Expand Down
16 changes: 14 additions & 2 deletions t/plugin/ext-plugin/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ __DATA__
[[{
"uri": "/hello",
"plugins": {
"ext-plugin-pre-req": {},
"ext-plugin-post-req": {}
"ext-plugin-pre-req": {"a":"b"},
"ext-plugin-post-req": {"c":"d"}
},
"upstream": {
"nodes": {
Expand Down Expand Up @@ -128,6 +128,10 @@ sending rpc type: 2 data length:
receiving rpc type: 2 data length:
sending rpc type: 2 data length:
receiving rpc type: 2 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 2 data length:
receiving rpc type: 2 data length:
sending rpc type: 2 data length:
Expand Down Expand Up @@ -256,6 +260,14 @@ sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
sending rpc type: 1 data length:
receiving rpc type: 1 data length:
--- error_log
flush conf token lrucache
--- no_error_log
Expand Down

0 comments on commit 174044e

Please sign in to comment.