Repository navigation
fix(router): report removal failures instead of silently succeeding - #1330
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 18, 2026 14:28
FlorentinDUBOIS
force-pushed
the
fix/router-equality
branch
from
September 18, 2026 16:02
344e6bd to
f8f2f05
Compare
Two defects let a frontend removal answer `Ok` while leaving the route in place and still routing traffic. `PathRule`'s hand-written `PartialEq` had arms for `Prefix` and `Regex` only, so `(Equals, Equals)` fell into `_ => false` and two identical `PathRule::Equals` compared unequal. `remove_tree_rule`'s `retain` then matched nothing and returned `true` unconditionally, so `remove_http_front` reported success for a path-equals frontend it had not removed. The same asymmetry meant such a frontend could never be deduplicated on add. A duplicate `--path-equals` `AddHttpFrontend` now returns `RouterError::AddRoute`, which is the answer `Prefix` and `Regex` frontends have always given. `PathRule` carries neither an `Eq` nor a `Hash` impl and is used as no map or set key, so restoring reflexivity introduces no `eq`/`hash` inconsistency. `TrieNode::remove_recursive` diverged between its two regex-segment arms: the `pos > 0` arm never pruned an emptied subtree, and the `pos == 0` arm retained on the regex alone, discarding every sibling domain under the same segment. Both arms now recurse into the matching subtree and drop the entry only once that subtree is empty. Removal uses `Vec::remove` rather than `swap_remove` because `lookup` and `lookup_with_path` both return on the first matching regex, which makes `regexps` order part of routing behaviour. The nine existing assertions these defects tripped are unchanged; only their causes are fixed. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/router-equality
branch
from
September 18, 2026 17:39
f8f2f05 to
795b95d
Compare
pull Bot
pushed a commit
to jrcribb/sozu
that referenced
this pull request
Sep 19, 2026
…ling In the pattern trie a domain whose leftmost label is a regex (`/test[0-9]/.example.com`) and a deeper domain sharing that segment (`foo./test[0-9]/.example.com`) live in the same `(regex, subtree)` entry: the first as the subtree's own value, the second as a child of it. `insert_recursive`'s `pos == 0` arm returned `InsertResult::Existing` unconditionally, justified by a comment claiming the subtree was already a value-bearing leaf built by `TrieNode::new`. That premise is false when the entry was created by the `pos > 0` branch, which builds a valueless `TrieNode::root()`. Inserting the deeper domain first therefore made the leftmost-regex host permanently un-insertable: the second insert answered `Existing` and stored nothing. Debug builds panicked the worker from a control-plane `AddHttpFrontend`, on `add_tree_rule`'s post-condition. Release builds reported success, listed the frontend in `sozu query frontends`, and never routed it — the main process recorded a frontend the data plane did not have. Pre-existing; PR sozu-proxy#1330 fixed `remove_recursive` and left this path untouched. The arm now asks the slot through a new `insert_own_value`: free answers `Ok`, occupied answers `Existing`. The empty-key arm is deliberately not reused, because on the remove side it is a query and on the insert side it is validation — routing an insert through it would make every leading-dot hostname insertable, including as a TLS certificate name, which `CertificateResolver::add_certificate` rejects by dry-running the same trie. Three comments resting on the same false premise are corrected, and the no-dot arm's soundness is documented: it is safe only because the two `children.insert` sites use disjoint key spaces, one keyed by a dotless segment and one by a key that always starts with a dot. `doc/configure.md` claimed configuration order does not affect routing. It does, in ways the manual had wrong in six separate dimensions, so the precedence section is rewritten and pinned by fourteen tests: - `PREFIX` rules: longest match wins among rules whose method matches, with an equal-length tie going to the last declared. - `REGEX` and `EQUALS`: the scan returns on the first match, so the first declared wins, and neither type outranks the other. - a matching `EQUALS` or `REGEX` beats a longer `PREFIX` in either order, but only when it carries a method the request matches. - without a method the scan does not short-circuit, so the last declared wins and only a prefix spanning the whole request path displaces a regex. - a rule whose method is set but does not match is skipped entirely, whatever its path type. - the request path is the request-target including any query string, which inverts the whole-path case and stops `EQUALS` matching at all. Path regexes are documented as unanchored, which they are: the `\A...\z` work of 2.0.0 applies to hostname segments only. Whether they should be anchored is sozu#1350. Hostname overlap is stated as not resolved by declaration order, without describing what does resolve it: that behaviour attaches an exact-host rule to a matching regex segment's leaf and is sozu#1351. Signed-off-by: Florentin Dubois <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Impact
Two defects let a frontend removal answer
Okwhile leaving the route in place and still routing traffic.PathRuleequality was not reflexiveThe hand-written
PartialEqhad arms forPrefixandRegexonly, so(Equals, Equals)fell into_ => falseand two identicalPathRule::Equalscompared unequal.remove_tree_rule'sretainthen matched nothing and returnedtrueunconditionally, soremove_http_frontreported success for a path-equals frontend it had not removed. The same asymmetry meant such a frontend could never be deduplicated on add.Pre/Postremoval returnsfalse→RouterError::RemoveRoute, so those failed loudly; only theTreepath was silent.Regex domain removal took out siblings
TrieNode::remove_recursivediverged between its two regex-segment arms: thepos > 0arm never pruned an emptied subtree, and thepos == 0arm retained on the regex alone, discarding every sibling domain under the same segment. Both arms now recurse into the matching subtree and drop the entry only once that subtree is empty.Removal uses
Vec::removerather thanswap_removedeliberately:lookupandlookup_with_pathboth return on the first matching regex, which makesregexpsorder part of routing behaviour.Observable API change
A duplicate
--path-equalsAddHttpFrontendnow returnsRouterError::AddRouteinstead of silently storing a second, unreachable copy. This is the answerPrefixandRegexfrontends have always given, so state replay becomes consistent rather than newly strict. Reviewed for dependants: no existing test, e2e or doc relied on the old silent success, and the command path cannot reach it anyway becauseConfigState::add_http_frontendalready refuses a duplicate route key withExists.Why CI never caught this
add_tree_rulecarries a pre-existing assertion that a freshly inserted tree domain resolves to its inserted rule. Onmainthat fires on the firstEqualsadd in a debug build — somainbeing green is itself proof that no existing test ever added a path-equals frontend through the router.Tests
Three red-then-green observations, each with a
To SEE THIS RED:block naming its mutation; an independent reviewer re-executed two of them and reproduced both documented panics verbatim.Checked and confirmed while making the change:
PathRulecarries neither anEqnor aHashimpl and is used as no map or set key, so restoring reflexivity introduces noeq/hashinconsistency.The nine existing assertions these defects tripped are unchanged — only their causes are fixed. Unlike the wire-derived assertions elsewhere in this batch, these are correct and each has a release-mode consequence.
Commands run
plus the
msrv-fullcell including the full e2e suite.Docs
doc/configure.mdanddoc/configure_cli.mddescribe path matching semantics, which are unchanged; neither documents add/remove equality or trie pruning.CHANGELOG.mdupdated.Adjacent pre-existing bug, not fixed here
While reviewing this branch,
insert_recursive'spos == 0arm was found to returnInsertResult::Existingwhen the regex entry already exists without checking that the subtree holds a value — so inserting the deeper domain first makes the leftmost-regex host permanently un-insertable.insert_recursiveis untouched by this diff, and the new sibling test picks the working insertion order, so it is not covered here. Flagged for a separate change.