Skip to content

sort_route does not consider vars condition count as tiebreaker #157

@janiussyafiq

Description

@janiussyafiq

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions