Skip to content

Commit

Permalink
fix(ext-plugin): don't use stale key (apache#5782)
Browse files Browse the repository at this point in the history
Co-authored-by: sunaowei <sunaowei@neild>
  • Loading branch information
2 people authored and bzp2010 committed Dec 30, 2021
1 parent 8cffb03 commit fd5db2c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions apisix/plugins/ext-plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ local type = type


local events_list
local lrucache = core.lrucache.new({
type = "plugin",
invalid_stale = true,
ttl = helper.get_conf_token_cache_time(),
})

local function new_lrucache()
return core.lrucache.new({
type = "plugin",
invalid_stale = true,
ttl = helper.get_conf_token_cache_time(),
})
end
local lrucache = new_lrucache()

local shdict_name = "ext-plugin"
local shdict = ngx.shared[shdict_name]

local schema = {
type = "object",
Expand Down Expand Up @@ -588,15 +595,14 @@ rpc_call = function (ty, conf, ctx, ...)
end


local function create_lrucache()
local function recreate_lrucache()
flush_token()

if lrucache then
core.log.warn("flush conf token lrucache")
end

lrucache = core.lrucache.new({
type = "plugin",
ttl = helper.get_conf_token_cache_time(),
})
lrucache = new_lrucache()
end


Expand All @@ -620,7 +626,7 @@ function _M.communicate(conf, ctx, plugin_name)
end

core.log.warn("refresh cache and try again")
create_lrucache()
recreate_lrucache()
end

core.log.error(err)
Expand Down Expand Up @@ -717,7 +723,7 @@ function _M.init_worker()
)

-- flush cache when runner exited
events.register(create_lrucache, events_list._source, events_list.runner_exit)
events.register(recreate_lrucache, events_list._source, events_list.runner_exit)

-- note that the runner is run under the same user as the Nginx master
if process.type() == "privileged agent" then
Expand Down

0 comments on commit fd5db2c

Please sign in to comment.