Skip to content

Commit f5d7a89

Browse files
committed
Merge remote-tracking branch 'origin/release-v1.109' into matrix-org-hotfixes
2 parents b03e8cd + 8c4937b commit f5d7a89

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

changelog.d/17275.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where OTKs were not always included in `/sync` response when using workers. Introduced v1.109.0rc1.

changelog.d/17292.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where `/sync` could get stuck due to edge case in device lists handling. Introduced in v1.109.0rc1.

synapse/handlers/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ async def _wait_for_sync_for_user(
545545
)
546546
)
547547

548-
cache_context.should_cache = False
548+
cache_context.should_cache = False # Don't cache empty responses
549549
return SyncResult.empty(
550550
since_token, one_time_keys_count, unused_fallback_key_types
551551
)

synapse/storage/databases/main/devices.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def __init__(
108108
("device_lists_outbound_pokes", "instance_name", "stream_id"),
109109
("device_lists_changes_in_room", "instance_name", "stream_id"),
110110
("device_lists_remote_pending", "instance_name", "stream_id"),
111+
(
112+
"device_lists_changes_converted_stream_position",
113+
"instance_name",
114+
"stream_id",
115+
),
111116
],
112117
sequence_name="device_lists_sequence",
113118
writers=["master"],
@@ -2396,15 +2401,16 @@ async def get_device_change_last_converted_pos(self) -> Tuple[int, str]:
23962401
`FALSE` have not been converted.
23972402
"""
23982403

2399-
return cast(
2400-
Tuple[int, str],
2401-
await self.db_pool.simple_select_one(
2402-
table="device_lists_changes_converted_stream_position",
2403-
keyvalues={},
2404-
retcols=["stream_id", "room_id"],
2405-
desc="get_device_change_last_converted_pos",
2406-
),
2404+
# There should be only one row in this table, though we want to
2405+
# future-proof ourselves for when we have multiple rows (one for each
2406+
# instance). So to handle that case we take the minimum of all rows.
2407+
rows = await self.db_pool.simple_select_list(
2408+
table="device_lists_changes_converted_stream_position",
2409+
keyvalues={},
2410+
retcols=["stream_id", "room_id"],
2411+
desc="get_device_change_last_converted_pos",
24072412
)
2413+
return cast(Tuple[int, str], min(rows))
24082414

24092415
async def set_device_change_last_converted_pos(
24102416
self,
@@ -2419,6 +2425,10 @@ async def set_device_change_last_converted_pos(
24192425
await self.db_pool.simple_update_one(
24202426
table="device_lists_changes_converted_stream_position",
24212427
keyvalues={},
2422-
updatevalues={"stream_id": stream_id, "room_id": room_id},
2428+
updatevalues={
2429+
"stream_id": stream_id,
2430+
"instance_name": self._instance_name,
2431+
"room_id": room_id,
2432+
},
24232433
desc="set_device_change_last_converted_pos",
24242434
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--
2+
-- This file is licensed under the Affero General Public License (AGPL) version 3.
3+
--
4+
-- Copyright (C) 2024 New Vector, Ltd
5+
--
6+
-- This program is free software: you can redistribute it and/or modify
7+
-- it under the terms of the GNU Affero General Public License as
8+
-- published by the Free Software Foundation, either version 3 of the
9+
-- License, or (at your option) any later version.
10+
--
11+
-- See the GNU Affero General Public License for more details:
12+
-- <https://www.gnu.org/licenses/agpl-3.0.html>.
13+
14+
-- Add `instance_name` columns to stream tables to allow them to be used with
15+
-- `MultiWriterIdGenerator`
16+
ALTER TABLE device_lists_changes_converted_stream_position ADD COLUMN instance_name TEXT;

0 commit comments

Comments
 (0)