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(pdk) kong.response.get_source() to return error on plugin throws runtime exception #8599

Merged
merged 5 commits into from
Apr 7, 2022
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 kong/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ local function execute_access_plugins_iterator(plugins_iterator, ctx)
status_code = 500,
content = { message = "An unexpected error occurred" },
}

-- plugin that throws runtime exception should be marked as `error`
ctx.KONG_UNEXPECTED = true
end

reset_plugin_context(ctx, old_ws)
Expand Down
44 changes: 44 additions & 0 deletions spec/02-integration/05-proxy/04-plugins_triggering_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,37 @@ for _, strategy in helpers.each_strategy() do
}
end

do
-- plugin to mock runtime exception
local mock_one_fn = [[
local nilValue = nil
kong.log.info('test' .. nilValue)
]]

local mock_two_fn = [[
ngx.header['X-Source'] = kong.response.get_source()
]]

local mock_service = bp.services:insert {
name = "runtime_exception",
}

bp.routes:insert {
hosts = { "runtime_exception" },
protocols = { "http" },
service = mock_service,
}

bp.plugins:insert {
name = "pre-function",
service = { id = mock_service.id },
config = {
["access"] = { mock_one_fn },
["header_filter"] = { mock_two_fn },
},
}
end

do
-- global plugin to catch Nginx-produced client errors
bp.plugins:insert {
Expand Down Expand Up @@ -1022,6 +1053,19 @@ for _, strategy in helpers.each_strategy() do
assert.res_status(504, res) -- Gateway Timeout
assert.equal("timeout", res.headers["Log-Plugin-Service-Matched"])
end)

it("kong.response.get_source() returns \"error\" if plugin runtime exception occurs, FTI-3200", function()
local res = assert(proxy_client:send {
method = "GET",
path = "/status/200",
headers = {
["Host"] = "runtime_exception"
}
})
local body = assert.res_status(500, res)
assert.same("body_filter", body)
assert.equal("error", res.headers["X-Source"])
end)
end)

describe("plugin's init_worker", function()
Expand Down