@@ -898,8 +898,14 @@ class DeviceHandler(DeviceWorkerHandler):
898898 def __init__ (self , hs : "HomeServer" ):
899899 super ().__init__ (hs )
900900
901- # TODO(quenting): we can't have use the federation_sender on non-fedsender/master workers
902- # self.federation_sender = hs.get_federation_sender()
901+ # We only need to poke the federation sender explicitly if its on the
902+ # same instance. Other federation sender instances will get notified by
903+ # `synapse.app.generic_worker.FederationSenderHandler` when it sees it
904+ # in the device lists stream.
905+ self .federation_sender = None
906+ if hs .should_send_federation ():
907+ self .federation_sender = hs .get_federation_sender ()
908+
903909 self ._storage_controllers = hs .get_storage_controllers ()
904910
905911 self .device_list_updater = DeviceListUpdater (hs , self )
@@ -1098,16 +1104,15 @@ async def _handle_new_device_update_async(self) -> None:
10981104 # Notify replication that we've updated the device list stream.
10991105 self .notifier .notify_replication ()
11001106
1101- if hosts :
1107+ if hosts and self . federation_sender :
11021108 logger .info (
11031109 "Sending device list update notif for %r to: %r" ,
11041110 user_id ,
11051111 hosts ,
11061112 )
1107- # TODO(quenting): do we need this?
1108- # await self.federation_sender.send_device_messages(
1109- # hosts, immediate=False
1110- # )
1113+ await self .federation_sender .send_device_messages (
1114+ hosts , immediate = False
1115+ )
11111116 # TODO: when called, this isn't in a logging context.
11121117 # This leads to log spam, sentry event spam, and massive
11131118 # memory usage.
@@ -1219,10 +1224,10 @@ async def handle_room_un_partial_stated(self, room_id: str) -> None:
12191224
12201225 # Notify things that device lists need to be sent out.
12211226 self .notifier .notify_replication ()
1222- # TODO(quenting): do we need this?
1223- # await self.federation_sender.send_device_messages(
1224- # potentially_changed_hosts, immediate=False
1225- # )
1227+ if self . federation_sender :
1228+ await self .federation_sender .send_device_messages (
1229+ potentially_changed_hosts , immediate = False
1230+ )
12261231
12271232
12281233def _update_device_from_client_ips (
0 commit comments