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

Ensure that remote users' device list resyncing always happens on master #9043

Merged
merged 5 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/9043.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for handling and persistence of to-device messages to happen on worker processes.
17 changes: 13 additions & 4 deletions synapse/handlers/devicemessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
set_tag,
start_active_span,
)
from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet
from synapse.types import JsonDict, UserID, get_domain_from_id
from synapse.util import json_encoder
from synapse.util.stringutils import random_string
Expand All @@ -50,7 +51,17 @@ def __init__(self, hs: "HomeServer"):
"m.direct_to_device", self.on_direct_to_device_edu
)

self._device_list_updater = hs.get_device_handler().device_list_updater
# The handler to call when we think a user's device list might be out of
# sync. We do all device list resyncing on the master instance, so if
# we're on a worker we hit the device resync replication API.
if hs.config.worker.worker_app is None:
richvdh marked this conversation as resolved.
Show resolved Hide resolved
self._user_device_resync = (
hs.get_device_handler().device_list_updater.user_device_resync
)
else:
self._user_device_resync = ReplicationUserDevicesResyncRestServlet.make_client(
hs
)

async def on_direct_to_device_edu(self, origin: str, content: JsonDict) -> None:
local_messages = {}
Expand Down Expand Up @@ -138,9 +149,7 @@ async def _check_for_unknown_devices(
await self.store.mark_remote_user_device_cache_as_stale(sender_user_id)

# Immediately attempt a resync in the background
run_in_background(
self._device_list_updater.user_device_resync, sender_user_id
)
run_in_background(self._user_device_resync, sender_user_id)

async def send_device_message(
self,
Expand Down