Skip to content

Commit

Permalink
fix(ext-plugin): don't use stale key (#5782)
Browse files Browse the repository at this point in the history
Co-authored-by: sunaowei <sunaowei@neild>
  • Loading branch information
S96EA and sunaowei authored Dec 14, 2021
1 parent 29a3b2a commit bb8ff5b
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 @@ -65,11 +65,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 @@ -668,17 +673,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 @@ -702,7 +704,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 @@ -799,7 +801,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 bb8ff5b

Please sign in to comment.