Skip to content

Commit

Permalink
[Backport release/3.3.x] fix(router): don't fail on route with multip…
Browse files Browse the repository at this point in the history
…le paths (#11159)

* fix(router): don't fail on route with multiple paths (#11158)

In `traditional_compatible` mode, the router would fail to work if a
route with multiple paths but no service would be created.

Fixes KAG-1961

(cherry picked from commit b0bd002)
  • Loading branch information
hanshuebner authored Jul 7, 2023
1 parent 53eaa40 commit 8f261b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
- Fixed a bug that causes `POST /config?flatten_errors=1` to throw an exception
and return a 500 error under certain circumstances.
[#10896](https://github.com/Kong/kong/pull/10896)
- Fix a bug that caused the router to fail in `traditional_compatible` mode when a route with multiple paths and no service was created.
[#11158](https://github.com/Kong/kong/pull/11158)

## 3.3.0

### Breaking Changes

#### Core

- The `traditional_compat` router mode has been made more compatible with the
- The `traditional_compatible` router mode has been made more compatible with the
behavior of `traditional` mode by splitting routes with multiple paths into
multiple atc routes with separate priorities. Since the introduction of the new
router in Kong Gateway 3.0, `traditional_compat` mode assigned only one priority
router in Kong Gateway 3.0, `traditional_compatible` mode assigned only one priority
to each route, even if different prefix path lengths and regular expressions
were mixed in a route. This was not how multiple paths were handled in the
`traditional` router and the behavior has now been changed so that a separate
Expand Down
3 changes: 1 addition & 2 deletions kong/router/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local atc = require("kong.router.atc")
local tb_new = require("table.new")
local tb_clear = require("table.clear")
local tb_nkeys = require("table.nkeys")
local tablex = require("pl.tablex")
local uuid = require("resty.jit-uuid")
local utils = require("kong.tools.utils")

Expand Down Expand Up @@ -336,7 +335,7 @@ local function split_route_by_path_into(route_and_service, routes_and_services_s
end

-- make sure that route_and_service contains only the two expected entries, route and service
assert(tablex.size(route_and_service) == 2)
assert(tb_nkeys(route_and_service) == 1 or tb_nkeys(route_and_service) == 2)

local grouped_paths = group_by(
route_and_service.route.paths,
Expand Down
15 changes: 15 additions & 0 deletions spec/01-unit/08-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4729,5 +4729,20 @@ for _, flavor in ipairs({ "traditional", "traditional_compatible" }) do
end)

end)

it("[can create route with multiple paths and no service]", function()
local use_case = {
-- regex + prefix
{
route = {
id = "e8fb37f1-102d-461e-9c51-6608a6bb8101",
paths = {
"/foo",
"/foo/bar/baz"
},
},
}}
assert(new_router(use_case))
end)
end)
end

0 comments on commit 8f261b7

Please sign in to comment.