Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix bug /sync returning 404 #12729

Merged
merged 3 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12729.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix uncommon bug where `/sync` would break for a user. Broke in v1.58.0.
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 11 additions & 8 deletions synapse/storage/databases/main/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,17 @@ async def get_room_event_before_stream_ordering(
"""

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble understanding how #12319 broke things. The previous code did a get_recent_events_for_room, which looks like it doesn't check for rejection either?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hmm, you're right. The PR did make it worse though as the query actually doubles the specified limit (to take account of filtering), so before we'd have to have two rejected events next to each other to hit the bug

ORDER BY stream_ordering DESC
LIMIT 1
"""
txn.execute(sql, (room_id, stream_ordering))
return cast(Optional[Tuple[int, int, str]], txn.fetchone())

Expand Down