Skip to content

Commit 1dc2956

Browse files
authored
Move registrations off the main worker (#18552)
This is mainly moving a few store methods around. Note that this doesn't yet remove the replication servlet to avoid breaking during rollout.
1 parent 66daf0b commit 1dc2956

File tree

6 files changed

+182
-189
lines changed

6 files changed

+182
-189
lines changed

changelog.d/18552.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow user registrations to be done on workers.

docs/upgrade.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ each upgrade are complete before moving on to the next upgrade, to avoid
117117
stacking them up. You can monitor the currently running background updates with
118118
[the Admin API](usage/administration/admin_api/background_updates.html#status).
119119
120+
# Upgrading to v1.135.0
121+
122+
## `on_user_registration` module API callback may now run on any worker
123+
124+
Previously, the `on_user_registration` callback would only run on the main
125+
process. Modules relying on this callback must assume that they may now be
126+
called from any worker, not just the main process.
127+
120128
# Upgrading to v1.134.0
121129
122130
## ICU bundled with Synapse

synapse/app/generic_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class GenericWorkerStore(
118118
# FIXME(https://github.com/matrix-org/synapse/issues/3714): We need to add
119119
# UserDirectoryStore as we write directly rather than going via the correct worker.
120120
UserDirectoryStore,
121-
StatsStore,
122121
UIAuthWorkerStore,
123122
EndToEndRoomKeyStore,
124123
PresenceStore,
@@ -154,6 +153,7 @@ class GenericWorkerStore(
154153
StreamWorkerStore,
155154
EventsWorkerStore,
156155
RegistrationWorkerStore,
156+
StatsStore,
157157
SearchStore,
158158
TransactionWorkerStore,
159159
LockStore,

synapse/handlers/register.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
from synapse.replication.http.login import RegisterDeviceReplicationServlet
5050
from synapse.replication.http.register import (
5151
ReplicationPostRegisterActionsServlet,
52-
ReplicationRegisterServlet,
5352
)
5453
from synapse.spam_checker_api import RegistrationBehaviour
5554
from synapse.types import GUEST_USER_ID_PATTERN, RoomAlias, UserID, create_requester
@@ -120,7 +119,6 @@ def __init__(self, hs: "HomeServer"):
120119
self._spam_checker_module_callbacks = hs.get_module_api_callbacks().spam_checker
121120

122121
if hs.config.worker.worker_app:
123-
self._register_client = ReplicationRegisterServlet.make_client(hs)
124122
self._register_device_client = RegisterDeviceReplicationServlet.make_client(
125123
hs
126124
)
@@ -738,37 +736,20 @@ async def register_with_store(
738736
shadow_banned: Whether to shadow-ban the user
739737
approved: Whether to mark the user as approved by an administrator
740738
"""
741-
if self.hs.config.worker.worker_app:
742-
await self._register_client(
743-
user_id=user_id,
744-
password_hash=password_hash,
745-
was_guest=was_guest,
746-
make_guest=make_guest,
747-
appservice_id=appservice_id,
748-
create_profile_with_displayname=create_profile_with_displayname,
749-
admin=admin,
750-
user_type=user_type,
751-
address=address,
752-
shadow_banned=shadow_banned,
753-
approved=approved,
754-
)
755-
else:
756-
await self.store.register_user(
757-
user_id=user_id,
758-
password_hash=password_hash,
759-
was_guest=was_guest,
760-
make_guest=make_guest,
761-
appservice_id=appservice_id,
762-
create_profile_with_displayname=create_profile_with_displayname,
763-
admin=admin,
764-
user_type=user_type,
765-
shadow_banned=shadow_banned,
766-
approved=approved,
767-
)
739+
await self.store.register_user(
740+
user_id=user_id,
741+
password_hash=password_hash,
742+
was_guest=was_guest,
743+
make_guest=make_guest,
744+
appservice_id=appservice_id,
745+
create_profile_with_displayname=create_profile_with_displayname,
746+
admin=admin,
747+
user_type=user_type,
748+
shadow_banned=shadow_banned,
749+
approved=approved,
750+
)
768751

769-
# Only call the account validity module(s) on the main process, to avoid
770-
# repeating e.g. database writes on all of the workers.
771-
await self._account_validity_handler.on_user_registration(user_id)
752+
await self._account_validity_handler.on_user_registration(user_id)
772753

773754
async def register_device(
774755
self,

synapse/replication/http/register.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
logger = logging.getLogger(__name__)
3434

3535

36+
# FIXME(2025-07-22): Remove this on the next release, this may only be used
37+
# during rollout to Synapse 1.134 and can be removed after that release.
3638
class ReplicationRegisterServlet(ReplicationEndpoint):
3739
"""Register a new user"""
3840

0 commit comments

Comments
 (0)