diff options
author | Erik Johnston <erikj@jki.re> | 2019-01-18 12:17:04 +0000 |
---|---|---|
committer | Amber Brown <hawkowl@atleastfornow.net> | 2019-01-18 23:17:04 +1100 |
commit | 25dd56ace36e9d3dbb717a34c9b9051b243f84ad (patch) | |
tree | e90eb41341272b569f9c4d2e74fa2f892f6bc981 | |
parent | Tweak code coverage settings (#4400) (diff) | |
download | synapse-25dd56ace36e9d3dbb717a34c9b9051b243f84ad.tar.xz |
Fix race when persisting create event (#4404)
* Fix race when persisting create event When persisting a chunk of DAG it is sometimes requried to do a state resolution, which requires knowledge of the room version. If this happens while we're persisting the create event then we need to use that event rather than attempting to look it up in the database.
-rw-r--r-- | changelog.d/4404.bugfix | 1 | ||||
-rw-r--r-- | synapse/storage/events.py | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/changelog.d/4404.bugfix b/changelog.d/4404.bugfix new file mode 100644 index 0000000000..5d40a3a60b --- /dev/null +++ b/changelog.d/4404.bugfix @@ -0,0 +1 @@ +Fix potential bug where creating or joining a room could fail diff --git a/synapse/storage/events.py b/synapse/storage/events.py index 2047110b1d..79e0276de6 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -739,7 +739,18 @@ class EventsStore(StateGroupWorkerStore, EventFederationStore, EventsWorkerStore } events_map = {ev.event_id: ev for ev, _ in events_context} - room_version = yield self.get_room_version(room_id) + + # We need to get the room version, which is in the create event. + # Normally that'd be in the database, but its also possible that we're + # currently trying to persist it. + room_version = None + for ev, _ in events_context: + if ev.type == EventTypes.Create and ev.state_key == "": + room_version = ev.content.get("room_version", "1") + break + + if not room_version: + room_version = yield self.get_room_version(room_id) logger.debug("calling resolve_state_groups from preserve_events") res = yield self._state_resolution_handler.resolve_state_groups( |