Skip to content

Fix before_all filters running twice#758

Merged
sdogruyol merged 1 commit into
masterfrom
fix-757
Jun 10, 2026
Merged

Fix before_all filters running twice#758
sdogruyol merged 1 commit into
masterfrom
fix-757

Conversation

@sdogruyol

@sdogruyol sdogruyol commented Jun 8, 2026

Copy link
Copy Markdown
Member

Fixes #757

Problem

After #737, global filters lived in the radix tree alongside path-specific ones. call_block_for_path_type ran the * filters explicitly, then the radix lookup for the request path matched the same * catch-all again — so before_all blocks ran twice per request (duplicated DB/auth calls).

A related edge case: before_all "/*" registers on a different key than before_all, so / could miss the global filter entirely when another wildcard filter (e.g. before_all "/api/*") was also registered.

Solution

Make duplicate execution structurally impossible by separating global filters from the radix tree at registration time:

  • _add_route_filter normalizes "*" and "/*" into a dedicated @global_filters hash — they never enter the radix tree
  • call_block_for_path_type simply runs global filters first, then the radix lookup for path-specific filters; the lookup can no longer re-match a global filter
  • before_all "/*" now behaves exactly like before_all, including on /

No dedup bookkeeping or per-request allocations needed.

@sdogruyol sdogruyol changed the title Fix filter execution order for #757 Fix before_all filters running twice Jun 10, 2026
@sdogruyol sdogruyol merged commit b73de3d into master Jun 10, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

before_x middleware seems to be triggering twice

1 participant