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

Commit dc671d3

Browse files
anoadragon453babolivierrichvdh
authored
Fix logic for dropping old events in fed queue (#11806)
Co-authored-by: Brendan Abolivier <[email protected]> Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 2d295a4 commit dc671d3

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

changelog.d/11806.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.40.0 that caused Synapse to fail to process incoming federation traffic after handling a large amount of events in a v1 room.

synapse/storage/databases/main/event_federation.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,10 @@ async def prune_staged_events_in_room(
14321432

14331433
if room_version.event_format == EventFormatVersions.V1:
14341434
for prev_event_tuple in prev_events:
1435-
if not isinstance(prev_event_tuple, list) or len(prev_events) != 2:
1435+
if (
1436+
not isinstance(prev_event_tuple, list)
1437+
or len(prev_event_tuple) != 2
1438+
):
14361439
logger.info("Invalid prev_events for %s", event_id)
14371440
break
14381441

tests/storage/test_event_federation.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from typing import Tuple, Union
16+
1517
import attr
1618
from parameterized import parameterized
1719

18-
from synapse.api.room_versions import RoomVersions
20+
from synapse.api.room_versions import (
21+
KNOWN_ROOM_VERSIONS,
22+
EventFormatVersions,
23+
RoomVersion,
24+
)
1925
from synapse.events import _EventInternalMetadata
2026
from synapse.util import json_encoder
2127

@@ -506,11 +512,21 @@ def insert_event(txn):
506512
)
507513
self.assertSetEqual(difference, set())
508514

509-
def test_prune_inbound_federation_queue(self):
510-
"Test that pruning of inbound federation queues work"
515+
@parameterized.expand(
516+
[(room_version,) for room_version in KNOWN_ROOM_VERSIONS.values()]
517+
)
518+
def test_prune_inbound_federation_queue(self, room_version: RoomVersion):
519+
"""Test that pruning of inbound federation queues work"""
511520

512521
room_id = "some_room_id"
513522

523+
def prev_event_format(prev_event_id: str) -> Union[Tuple[str, dict], str]:
524+
"""Account for differences in prev_events format across room versions"""
525+
if room_version.event_format == EventFormatVersions.V1:
526+
return prev_event_id, {}
527+
528+
return prev_event_id
529+
514530
# Insert a bunch of events that all reference the previous one.
515531
self.get_success(
516532
self.store.db_pool.simple_insert_many(
@@ -529,7 +545,9 @@ def test_prune_inbound_federation_queue(self):
529545
room_id,
530546
0,
531547
f"$fake_event_id_{i + 1}",
532-
json_encoder.encode({"prev_events": [f"$fake_event_id_{i}"]}),
548+
json_encoder.encode(
549+
{"prev_events": [prev_event_format(f"$fake_event_id_{i}")]}
550+
),
533551
"{}",
534552
)
535553
for i in range(500)
@@ -541,12 +559,12 @@ def test_prune_inbound_federation_queue(self):
541559
# Calling prune once should return True, i.e. a prune happen. The second
542560
# time it shouldn't.
543561
pruned = self.get_success(
544-
self.store.prune_staged_events_in_room(room_id, RoomVersions.V6)
562+
self.store.prune_staged_events_in_room(room_id, room_version)
545563
)
546564
self.assertTrue(pruned)
547565

548566
pruned = self.get_success(
549-
self.store.prune_staged_events_in_room(room_id, RoomVersions.V6)
567+
self.store.prune_staged_events_in_room(room_id, room_version)
550568
)
551569
self.assertFalse(pruned)
552570

0 commit comments

Comments
 (0)