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(router/atc): reset rebuilding flag if route has no id #12654

Merged
merged 3 commits into from
Mar 14, 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
5 changes: 5 additions & 0 deletions changelog/unreleased/kong/fix-router-rebuing-flag.yml
ADD-SP marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
message: |
Fixed an issue where router may not work correctly
when the routes configuration changed.
type: bugfix
scope: Core
1 change: 1 addition & 0 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ local function new_from_previous(routes, get_exp_and_priority, old_router)
local route_id = route.id

if not route_id then
old_router.rebuilding = false
return nil, "could not categorize route"
end

Expand Down
40 changes: 40 additions & 0 deletions spec/01-unit/08-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,46 @@ for _, flavor in ipairs({ "traditional", "traditional_compatible", "expressions"
assert.spy(add_matcher).was_called(2)
assert.spy(remove_matcher).was_called(2)
end)

it("works well if route has no proper id", function()
local wrong_use_case = {
{
service = service,
route = {
id = nil, -- no id here
paths = { "/foo", },
updated_at = 100,
},
},
}

local nrouter = new_router(wrong_use_case, router)
assert.is_nil(nrouter)
assert.falsy(router.rebuilding)

local use_case = {
{
service = service,
route = {
id = "e8fb37f1-102d-461e-9c51-6608a6bb8101",
paths = { "/foo1", },
updated_at = 100,
},
},
}

local nrouter = assert(new_router(use_case, router))

assert.equal(nrouter, router)
assert.falsy(router.rebuilding)

local match_t = nrouter:select("GET", "/foo1")
assert.truthy(match_t)
assert.same(use_case[1].route, match_t.route)

match_t = nrouter:select("GET", "/bar")
assert.falsy(match_t)
end)
end)

describe("check empty route fields", function()
Expand Down
Loading