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(core): fix an issue where Kong do not handle properly when Python and Javascript plugin server crashes #12582

Merged
merged 1 commit into from
Feb 20, 2024
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
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/plugin_server_restart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Plugin Server**: fix an issue where Kong fails to properly restart MessagePack-based pluginservers (used in Python and Javascript plugins, for example)"
type: bugfix
scope: Core
18 changes: 10 additions & 8 deletions kong/runloop/plugin_servers/mp_rpc.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local kong_global = require "kong.global"
local cjson = require "cjson.safe"
local _

local msgpack do
msgpack = require "MessagePack"
local nil_pack = msgpack.packers["nil"]
Expand Down Expand Up @@ -326,20 +328,20 @@ end


function Rpc:handle_event(plugin_name, conf, phase)
local instance_id = self.get_instance_id(plugin_name, conf)
local _, err = bridge_loop(self, instance_id, phase)
local instance_id, err = self.get_instance_id(plugin_name, conf)
if not err then
_, err = bridge_loop(self, instance_id, phase)
end

if err then
local ok, err2 = 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: ", err2)
end
local err_lowered = err:lower()

if str_find(err:lower(), "no plugin instance") then
if str_find(err_lowered, "no plugin instance") then
self.reset_instance(plugin_name, conf)
kong.log.warn(err)
return self:handle_event(plugin_name, conf, phase)
end

kong.log.err(err)
end
end
Expand Down
24 changes: 10 additions & 14 deletions kong/runloop/plugin_servers/pb_rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ end


function Rpc:handle_event(plugin_name, conf, phase)
local instance_id, res, err
instance_id, err = self.get_instance_id(plugin_name, conf)
local instance_id, err = self.get_instance_id(plugin_name, conf)
local res
if not err then
res, err = self:call("cmd_handle_event", {
instance_id = instance_id,
Expand All @@ -402,20 +402,16 @@ function Rpc:handle_event(plugin_name, conf, phase)
end

if not res or res == "" then
if err then
local err_lowered = err and err:lower() or ""

kong.log.err(err_lowered)
local err_lowered = err and err:lower() or "unknown error"

if err_lowered == "not ready" then
self.reset_instance(plugin_name, conf)
end
if str_find(err_lowered, "no plugin instance")
or str_find(err_lowered, "closed") then
self.reset_instance(plugin_name, conf)
return self:handle_event(plugin_name, conf, phase)
end
if str_find(err_lowered, "no plugin instance", nil, true)
or str_find(err_lowered, "closed", nil, true) then
self.reset_instance(plugin_name, conf)
kong.log.warn(err)
return self:handle_event(plugin_name, conf, phase)
end

kong.log.err(err)
end
end

Expand Down
Loading