From a4fa044c0058337a641a5486b4152d04c6aa3e05 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 3 Mar 2021 16:04:24 +0000 Subject: [PATCH] Fix 'rejected_events_metadata' background update (#9537) Turns out matrix.org has an event that has duplicate auth events (which really isn't supposed to happen, but here we are). This caused the background update to fail due to `UniqueViolation`. --- changelog.d/9537.bugfix | 1 + synapse/storage/databases/main/events_bg_updates.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/9537.bugfix diff --git a/changelog.d/9537.bugfix b/changelog.d/9537.bugfix new file mode 100644 index 000000000..033ab1c93 --- /dev/null +++ b/changelog.d/9537.bugfix @@ -0,0 +1 @@ +Fix rare edge case that caused a background update to fail if the server had rejected an event that had duplicate auth events. diff --git a/synapse/storage/databases/main/events_bg_updates.py b/synapse/storage/databases/main/events_bg_updates.py index c1626ccf2..cb6b1f8a0 100644 --- a/synapse/storage/databases/main/events_bg_updates.py +++ b/synapse/storage/databases/main/events_bg_updates.py @@ -696,7 +696,9 @@ class EventsBackgroundUpdatesStore(SQLBaseStore): ) if not has_event_auth: - for auth_id in event.auth_event_ids(): + # Old, dodgy, events may have duplicate auth events, which we + # need to deduplicate as we have a unique constraint. + for auth_id in set(event.auth_event_ids()): auth_events.append( { "room_id": event.room_id,