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 31, 2021
1 parent 4d74f63 commit f92b5d0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions apisix/plugins/ext-plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ 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]

Expand Down Expand Up @@ -657,17 +662,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 @@ -691,7 +693,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 @@ -788,7 +790,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 f92b5d0

Please sign in to comment.