summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2020-08-20 10:25:10 +0100
committerErik Johnston <erik@matrix.org>2020-08-24 16:57:01 +0100
commit2c74b2c3767ec7200adf7f3f23fb4fc570698cbc (patch)
treebc40421f59b11e6fd754bc3b59daf4f41a131577
parentRemove `ChainedIdGenerator`. (#8123) (diff)
downloadsynapse-github/erikj/fix_remote_join_predecessor.tar.xz
-rw-r--r--synapse/handlers/federation.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 5b270228e7..24e361a415 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -17,6 +17,7 @@
 
 """Contains handlers for federation events."""
 
+import collections
 import itertools
 import logging
 from collections.abc import Container
@@ -1368,11 +1369,25 @@ class FederationHandler(BaseHandler):
                 self.config.worker.writers.events, "events", max_stream_id
             )
 
-            # Check whether this room is the result of an upgrade of a room we already know
-            # about. If so, migrate over user information
-            predecessor = await self.store.get_room_predecessor(room_id)
+            # Check whether this room is the result of an upgrade of a room we
+            # already know about. If so, migrate over user information
+            #
+            # Note: we do this manually rather than asking the DB to avoid a
+            # race where the current state hasn't yet updated.
+            predecessor = None
+            for s in state:
+                if s.type == EventTypes.Create:
+                    predecessor = s.content.get("predecessor", None)
+
+                    # Ensure the key is a dictionary
+                    if not isinstance(predecessor, collections.abc.Mapping):
+                        predecessor = None
+
+                    break
+
             if not predecessor or not isinstance(predecessor.get("room_id"), str):
                 return event.event_id, max_stream_id
+
             old_room_id = predecessor["room_id"]
             logger.debug(
                 "Found predecessor for %s during remote join: %s", room_id, old_room_id