Bug
When two routes share the same priority and uri, sort_route tiebreaks by URI path length (#path_org). For identical paths (e.g. /*), this means insertion order wins — not specificity.
The result: a route with 1 vars condition is matched over a route with 2 vars conditions, even when the request satisfies both.
Ref: apache/apisix#9431
Root Cause
sort_route in radixtree.lua:
|
local function sort_route(route_a, route_b) |
|
if route_a.priority == route_b.priority then |
|
return #route_a.path_org > #route_b.path_org |
|
end |
|
return (route_a.priority or 0) > (route_b.priority or 0) |
|
end |
When priority and path_org are both equal, the sort is a no-op - insert_tab_in_order preserves insertion order.
Expected Behavior
Among routes with equal priority and path, the one with more vars conditions should be tried first (more conditions = more specific).
Bug
When two routes share the same
priorityanduri,sort_routetiebreaks by URI path length (#path_org). For identical paths (e.g./*), this means insertion order wins — not specificity.The result: a route with 1
varscondition is matched over a route with 2varsconditions, even when the request satisfies both.Ref: apache/apisix#9431
Root Cause
sort_routeinradixtree.lua:lua-resty-radixtree/lib/resty/radixtree.lua
Lines 206 to 211 in 8166eea
When priority and path_org are both equal, the sort is a no-op - insert_tab_in_order preserves insertion order.
Expected Behavior
Among routes with equal priority and path, the one with more vars conditions should be tried first (more conditions = more specific).