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 15:57:13 +0100
commitab73bf1c859630256ceb241f402e809804d01d21 (patch)
tree6e3e08d302704e73bf29d6c114bb3fa7f39b2e08
parentAdd multiwriter for events (diff)
downloadsynapse-ab73bf1c859630256ceb241f402e809804d01d21.tar.xz
Fix remote join predecessor race
-rw-r--r--synapse/handlers/federation.py14
-rw-r--r--synapse/handlers/message.py2
2 files changed, 14 insertions, 2 deletions
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index 5b270228e7..8391728bdb 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,9 +1369,20 @@ class FederationHandler(BaseHandler):
                 self.config.worker.writers.events, "events", max_stream_id
             )
 
+            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
+
             # 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)
+            # predecessor = await self.store.get_room_predecessor(room_id)
             if not predecessor or not isinstance(predecessor.get("room_id"), str):
                 return event.event_id, max_stream_id
             old_room_id = predecessor["room_id"]
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 67d9f95202..c955a86be0 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -675,7 +675,7 @@ class EventCreationHandler(object):
                     event.event_id,
                     prev_event.event_id,
                 )
-                return await self.store.get_stream_token_for_event(prev_event.event_id)
+                return await self.store.get_stream_id_for_event(prev_event.event_id)
 
         return await self.handle_new_client_event(
             requester=requester, event=event, context=context, ratelimit=ratelimit