lua-resty-radixtree icon indicating copy to clipboard operation
lua-resty-radixtree copied to clipboard

sort_route does not consider vars condition count as tiebreaker

Open janiussyafiq opened this issue 8 months ago • 0 comments

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: https://github.com/api7/lua-resty-radixtree/blob/8166eea3e1128ab83e741aa665685648c234cac8/lib/resty/radixtree.lua#L206-L211 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).

janiussyafiq avatar Apr 03 '26 03:04 janiussyafiq