Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 318f4e7

Browse files
authored
Be more tolerant of membership events in unknown rooms (#8110)
It turns out that not all out-of-band membership events are labelled as such, so we need to be more accepting here.
1 parent 592cdf7 commit 318f4e7

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

changelog.d/8110.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.12.0 which could cause `/sync` requests to fail with a 404 if you had a very old outstanding room invite.

synapse/events/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def is_out_of_band_membership(self) -> bool:
133133
rejection. This is needed as those events are marked as outliers, but
134134
they still need to be processed as if they're new events (e.g. updating
135135
invite state in the database, relaying to clients, etc).
136+
137+
(Added in synapse 0.99.0, so may be unreliable for events received before that)
136138
"""
137139
return self._dict.get("out_of_band_membership", False)
138140

synapse/storage/databases/main/events_worker.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -620,19 +620,38 @@ async def _get_events_from_db(self, event_ids, allow_rejected=False):
620620
room_version_id = row["room_version_id"]
621621

622622
if not room_version_id:
623-
# this should only happen for out-of-band membership events
624-
if not internal_metadata.get("out_of_band_membership"):
625-
logger.warning(
626-
"Room %s for event %s is unknown", d["room_id"], event_id
623+
# this should only happen for out-of-band membership events which
624+
# arrived before #6983 landed. For all other events, we should have
625+
# an entry in the 'rooms' table.
626+
#
627+
# However, the 'out_of_band_membership' flag is unreliable for older
628+
# invites, so just accept it for all membership events.
629+
#
630+
if d["type"] != EventTypes.Member:
631+
raise Exception(
632+
"Room %s for event %s is unknown" % (d["room_id"], event_id)
627633
)
628-
continue
629634

630-
# take a wild stab at the room version based on the event format
635+
# so, assuming this is an out-of-band-invite that arrived before #6983
636+
# landed, we know that the room version must be v5 or earlier (because
637+
# v6 hadn't been invented at that point, so invites from such rooms
638+
# would have been rejected.)
639+
#
640+
# The main reason we need to know the room version here (other than
641+
# choosing the right python Event class) is in case the event later has
642+
# to be redacted - and all the room versions up to v5 used the same
643+
# redaction algorithm.
644+
#
645+
# So, the following approximations should be adequate.
646+
631647
if format_version == EventFormatVersions.V1:
648+
# if it's event format v1 then it must be room v1 or v2
632649
room_version = RoomVersions.V1
633650
elif format_version == EventFormatVersions.V2:
651+
# if it's event format v2 then it must be room v3
634652
room_version = RoomVersions.V3
635653
else:
654+
# if it's event format v3 then it must be room v4 or v5
636655
room_version = RoomVersions.V5
637656
else:
638657
room_version = KNOWN_ROOM_VERSIONS.get(room_version_id)

0 commit comments

Comments
 (0)