prevent 500 error on cyclic space hierarchies #2036
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
continuwuation/continuwuity!2036
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Reaster/continuwuity:self-contained-room"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Requesting GET /_matrix/client/v1/rooms/{roomId}/hierarchy on a space whose graph contains a cycle — for example a space that
includes itself as a child, or two spaces that reference each other — fails with:
500 Internal Server Error
{"errcode":"M_UNKNOWN","error":"Space hierarchy is unreasonably large"}
This makes the space impossible to open in clients such as Element.
get_room_hierarchy_for_user in src/service/rooms/summary/mod.rs traverses the space tree depth-first using a stack of layers
(queue), but the only deduplication set it keeps is inaccessible_children. There is no visited-set for accessible rooms, so when
the graph contains a cycle, the same room is fetched and its children pushed again on every revisit. Each revisit adds a new
layer, so the traversal depth grows without bound.
Two factors then turn this into a 500:
not, so max_depth stays None and the depth guard never fires.
M_UNKNOWN / HTTP 500.
Additionally, even when max_depth is provided, a cycle currently produces duplicate room entries in the response, which violates
the spec: MSC2946 requires each room to appear at most once.
Changes
response. This terminates cycles naturally and guarantees room uniqueness as required by the spec.
depth-bounded.
since it is a property of the request target rather than a server fault.
The federation hierarchy endpoint (/_matrix/federation/v1/hierarchy) is unaffected: it only summarizes a single level and does
not use this traversal.
my deadass really just went "now what happend if i try to put the same space into itself?" and pouf space bricked wonderfully haha
🤨 I was under the impression that it was both legal and expected for a space to appear multiple times in the hierarchy output if it exists multiple times in the room graph
i don't know how it could possibly work to have the same space twice in a same space three without causing any recursion error when showing this three
i think theres no problem to see the same space appear multiple time in a same space "group" at different "branch" but if it happend more than one on the same "branch" (aka: at one point space Y contain space Y under itself) theres no way to not have a recursion issue
I think this is an acceptable change for now to at least keep recursive space hierarchies from becoming unrecoverable
This currently fails clippy, I'll approve it once that's fixed
done, it was just a one-liner issue
e1726d8733fc0b960622