Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pluginservers): workers invalidate instances #11370

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion kong/runloop/plugin_servers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function get_instance_id(plugin_name, conf)
-- some other thread is already starting an instance
-- prevent busy-waiting
ngx_sleep(SLEEP_STEP)

-- to prevent a potential dead loop when someone failed to release the ID
wait_count = wait_count + 1
if wait_count > MAX_WAIT_STEPS then
Expand Down Expand Up @@ -386,6 +386,7 @@ end


function plugin_servers.start()
-- only worker 0 managers the plugin server
if worker_id() == 0 then
local pluginserver_timer = proc_mgmt.pluginserver_timer

Expand All @@ -396,13 +397,20 @@ function plugin_servers.start()
end
end

-- workers != 0 still need to get plugin servers definitions
--
local connection_check_timer = proc_mgmt.connection_check_timer

for _, server_def in ipairs(proc_mgmt.get_server_defs()) do
if server_def.start_command then
native_timer_at(0, connection_check_timer, server_def)
end
end

-- in case plugin server restarts, all workers need to update their defs
kong.worker_events.register(function (data)
reset_instance(data.plugin_name, data.conf)
end, "plugin_server", "reset_instances")
end

function plugin_servers.stop()
Expand Down
26 changes: 17 additions & 9 deletions kong/runloop/plugin_servers/pb_rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,23 @@ function Rpc:handle_event(plugin_name, conf, phase)
end

if not res or res == "" then
if err == "not ready" then
self.reset_instance(plugin_name, conf)
return handle_not_ready(plugin_name)
end
if err and (str_find(err:lower(), "no plugin instance", 1, true)
or str_find(err:lower(), "closed", 1, true)) then
kong.log.warn(err)
self.reset_instance(plugin_name, conf)
return self:handle_event(plugin_name, conf, phase)
if err then
local ok, err = kong.worker_events.post("plugin_server", "reset_instances",
{ plugin_name = plugin_name, conf = conf })
if not ok then
kong.log.err("failed to post plugin_server reset_instances event: ", err)
end

if err == "not ready" then
self.reset_instance(plugin_name, conf)
return handle_not_ready(plugin_name)
end
if err and (str_find(err:lower(), "no plugin instance", 1, true)
or str_find(err:lower(), "closed", 1, true)) then
kong.log.warn(err)
self.reset_instance(plugin_name, conf)
return self:handle_event(plugin_name, conf, phase)
end
end
kong.log.err(err)
end
Expand Down
Loading