diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2022-05-03 21:27:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 21:27:52 +0100 |
commit | 96e0cdbc5af0563ee805ec4e588e1df14899af66 (patch) | |
tree | 16778bcb0ad585075158c154fa462cbd7eb8222d /synapse/storage/databases/main | |
parent | Bump Synapse minimum Python version to 3.7.1 (#12613) (diff) | |
download | synapse-96e0cdbc5af0563ee805ec4e588e1df14899af66.tar.xz |
Add a consistency check on events read from the database (#12620)
I've seen a few errors which can only plausibly be explained by the calculated event id for an event being different from the ID of the event in the database. It should be cheap to check this, so let's do so and raise an exception.
Diffstat (limited to 'synapse/storage/databases/main')
-rw-r--r-- | synapse/storage/databases/main/events_worker.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/events_worker.py b/synapse/storage/databases/main/events_worker.py index c31fc00eaa..0a48e5d29f 100644 --- a/synapse/storage/databases/main/events_worker.py +++ b/synapse/storage/databases/main/events_worker.py @@ -1094,6 +1094,18 @@ class EventsWorkerStore(SQLBaseStore): original_ev.internal_metadata.stream_ordering = row.stream_ordering original_ev.internal_metadata.outlier = row.outlier + # Consistency check: if the content of the event has been modified in the + # database, then the calculated event ID will not match the event id in the + # database. + if original_ev.event_id != event_id: + # it's difficult to see what to do here. Pretty much all bets are off + # if Synapse cannot rely on the consistency of its database. + raise RuntimeError( + f"Database corruption: Event {event_id} in room {d['room_id']} " + f"from the database appears to have been modified (calculated " + f"event id {original_ev.event_id})" + ) + event_map[event_id] = original_ev # finally, we can decide whether each one needs redacting, and build |