summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-05-16 12:06:56 +0100
committerGitHub <noreply@github.com>2022-05-16 12:06:56 +0100
commit8689230a55cf1bb8e959e993fd4b28dcee0716da (patch)
treee842602dc5e0b6b86c8fc98f867eef97994b76b7
parentother fixes (diff)
downloadsynapse-8689230a55cf1bb8e959e993fd4b28dcee0716da.tar.xz
Fix bug /sync returning 404 (#12729)
* Fix bug /sync returning 404

Fixes #12571
Diffstat (limited to '')
-rw-r--r--changelog.d/12729.bugfix1
-rw-r--r--synapse/storage/databases/main/stream.py19
2 files changed, 12 insertions, 8 deletions
diff --git a/changelog.d/12729.bugfix b/changelog.d/12729.bugfix
new file mode 100644
index 0000000000..07aae23ac0
--- /dev/null
+++ b/changelog.d/12729.bugfix
@@ -0,0 +1 @@
+Fix a bug introduced in Synapse 1.58.0 where `/sync` would fail if the most recent event in a room was rejected.
diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py
index 793e906630..3c3137fe64 100644
--- a/synapse/storage/databases/main/stream.py
+++ b/synapse/storage/databases/main/stream.py
@@ -743,14 +743,17 @@ class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
         """
 
         def _f(txn: LoggingTransaction) -> Optional[Tuple[int, int, str]]:
-            sql = (
-                "SELECT stream_ordering, topological_ordering, event_id"
-                " FROM events"
-                " WHERE room_id = ? AND stream_ordering <= ?"
-                " AND NOT outlier"
-                " ORDER BY stream_ordering DESC"
-                " LIMIT 1"
-            )
+            sql = """
+                SELECT stream_ordering, topological_ordering, event_id
+                FROM events
+                LEFT JOIN rejections USING (event_id)
+                WHERE room_id = ?
+                    AND stream_ordering <= ?
+                    AND NOT outlier
+                    AND rejections.reason IS NULL
+                ORDER BY stream_ordering DESC
+                LIMIT 1
+            """
             txn.execute(sql, (room_id, stream_ordering))
             return cast(Optional[Tuple[int, int, str]], txn.fetchone())