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

Commit

Permalink
Fix resync remote devices on receive PDU in worker mode. (#7815)
Browse files Browse the repository at this point in the history
The replication client requires that arguments are given as keyword
arguments, which was not done in this case. We also pull out the logic
so that we can catch and handle any exceptions raised, rather than
leaving them unhandled.
  • Loading branch information
erikjohnston authored Jul 10, 2020
1 parent e29c443 commit f1245dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/7815.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix detection of out of sync remote device lists when receiving events from remote users.
27 changes: 19 additions & 8 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
run_in_background,
)
from synapse.logging.utils import log_function
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet
from synapse.replication.http.federation import (
ReplicationCleanRoomRestServlet,
Expand Down Expand Up @@ -789,15 +790,25 @@ async def _process_received_pdu(
resync = True

if resync:
await self.store.mark_remote_user_device_cache_as_stale(event.sender)
run_as_background_process(
"resync_device_due_to_pdu", self._resync_device, event.sender
)

# Immediately attempt a resync in the background
if self.config.worker_app:
return run_in_background(self._user_device_resync, event.sender)
else:
return run_in_background(
self._device_list_updater.user_device_resync, event.sender
)
async def _resync_device(self, sender: str) -> None:
"""We have detected that the device list for the given user may be out
of sync, so we try and resync them.
"""

try:
await self.store.mark_remote_user_device_cache_as_stale(sender)

# Immediately attempt a resync in the background
if self.config.worker_app:
await self._user_device_resync(user_id=sender)
else:
await self._device_list_updater.user_device_resync(sender)
except Exception:
logger.exception("Failed to resync device for %s", sender)

@log_function
async def backfill(self, dest, room_id, limit, extremities):
Expand Down

0 comments on commit f1245dc

Please sign in to comment.