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): separate plugin server runtime data from kong configuration #14111

Merged
merged 3 commits into from
Jan 23, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "Fixed an issue where a GET request to the Admin API root `/` path would return a 500 server error"
type: bugfix
scope: Core
21 changes: 13 additions & 8 deletions kong/runloop/plugin_servers/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local cjson_decode = cjson.decode
local SIGTERM = 15


local server_rt = {} -- store runtime of plugin server like proc
local _M = {}


Expand Down Expand Up @@ -150,16 +151,19 @@ local function pluginserver_timer(premature, server_def)
end

kong.log.notice("[pluginserver] starting pluginserver process for ", server_def.name or "")
server_def.proc = assert(ngx_pipe.spawn("exec " .. server_def.start_command, {
ProBrian marked this conversation as resolved.
Show resolved Hide resolved
local proc = assert(ngx_pipe.spawn("exec " .. server_def.start_command, {
merge_stderr = true,
}))
server_rt[server_def.name] = {
proc = proc,
}
next_spawn = ngx.now() + 1
server_def.proc:set_timeouts(nil, nil, nil, 0) -- block until something actually happens
kong.log.notice("[pluginserver] started, pid ", server_def.proc:pid())
proc:set_timeouts(nil, nil, nil, 0) -- block until something actually happens
kong.log.notice("[pluginserver] started, pid ", proc:pid())

while true do
grab_logs(server_def.proc, server_def.name)
local ok, reason, status = server_def.proc:wait()
grab_logs(proc, server_def.name)
local ok, reason, status = proc:wait()

-- exited with a non 0 status
if ok == false and reason == "exit" and status == 127 then
Expand Down Expand Up @@ -205,12 +209,13 @@ function _M.stop_pluginservers()
-- only worker 0 manages plugin server processes
if worker_id() == 0 then -- TODO move to privileged worker?
for _, server_def in ipairs(kong_config.pluginservers) do
if server_def.proc then
local ok, err = server_def.proc:kill(SIGTERM)
local server = server_rt[server_def.name]
if server and server.proc then
local ok, err = server.proc:kill(SIGTERM)
if not ok then
kong.log.error("[pluginserver] failed to stop pluginserver '", server_def.name, ": ", err)
end
kong.log.notice("[pluginserver] successfully stopped pluginserver '", server_def.name, "', pid ", server_def.proc:pid())
kong.log.notice("[pluginserver] successfully stopped pluginserver '", server_def.name, "', pid ", server.proc:pid())
end
end
end
Expand Down
Loading