Skip to content

Commit

Permalink
fix(core): separate pluginserver runtime data from kong configuration (
Browse files Browse the repository at this point in the history
  • Loading branch information
ProBrian authored Jan 23, 2025
1 parent 6837e4d commit 7a505ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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, {
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

1 comment on commit 7a505ea

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong-dev:7a505eaa6870a5b9e7da914a32464635691f1038
Artifacts available https://github.com/Kong/kong/actions/runs/12928544608

Please sign in to comment.