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

Commit

Permalink
Add debugging to help diagnose lost device-list-update (#14268)
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh authored Oct 24, 2022
1 parent 6c82b37 commit 1469fed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog.d/14268.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add debugging to help diagnose lost device-list-update.
54 changes: 37 additions & 17 deletions synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ async def get_device_updates_by_remote(
destination, int(from_stream_id)
)
if not has_changed:
# debugging for https://github.com/matrix-org/synapse/issues/14251
issue_8631_logger.debug(
"%s: no change between %i and %i",
destination,
from_stream_id,
now_stream_id,
)
return now_stream_id, []

updates = await self.db_pool.runInteraction(
Expand Down Expand Up @@ -1848,7 +1855,7 @@ def _add_device_outbound_poke_to_stream_txn(
self,
txn: LoggingTransaction,
user_id: str,
device_ids: Iterable[str],
device_id: str,
hosts: Collection[str],
stream_ids: List[int],
context: Optional[Dict[str, str]],
Expand All @@ -1864,6 +1871,21 @@ def _add_device_outbound_poke_to_stream_txn(
stream_id_iterator = iter(stream_ids)

encoded_context = json_encoder.encode(context)
mark_sent = not self.hs.is_mine_id(user_id)

values = [
(
destination,
next(stream_id_iterator),
user_id,
device_id,
mark_sent,
now,
encoded_context if whitelisted_homeserver(destination) else "{}",
)
for destination in hosts
]

self.db_pool.simple_insert_many_txn(
txn,
table="device_lists_outbound_pokes",
Expand All @@ -1876,23 +1898,21 @@ def _add_device_outbound_poke_to_stream_txn(
"ts",
"opentracing_context",
),
values=[
(
destination,
next(stream_id_iterator),
user_id,
device_id,
not self.hs.is_mine_id(
user_id
), # We only need to send out update for *our* users
now,
encoded_context if whitelisted_homeserver(destination) else "{}",
)
for destination in hosts
for device_id in device_ids
],
values=values,
)

# debugging for https://github.com/matrix-org/synapse/issues/14251
if issue_8631_logger.isEnabledFor(logging.DEBUG):
issue_8631_logger.debug(
"Recorded outbound pokes for %s:%s with device stream ids %s",
user_id,
device_id,
{
stream_id: destination
for (destination, stream_id, _, _, _, _, _) in values
},
)

def _add_device_outbound_room_poke_txn(
self,
txn: LoggingTransaction,
Expand Down Expand Up @@ -1997,7 +2017,7 @@ def add_device_list_outbound_pokes_txn(
self._add_device_outbound_poke_to_stream_txn(
txn,
user_id=user_id,
device_ids=[device_id],
device_id=device_id,
hosts=hosts,
stream_ids=stream_ids,
context=context,
Expand Down

0 comments on commit 1469fed

Please sign in to comment.