summary refs log tree commit diff
path: root/synapse/handlers/register.py
diff options
context:
space:
mode:
authorKrombel <krombel@krombel.de>2018-03-28 14:45:28 +0200
committerKrombel <krombel@krombel.de>2018-03-28 14:45:28 +0200
commit6152e253d842eb4f72be975850450f00c0662e43 (patch)
tree5fa7c6cef720825e05076190c7d0e1f45565a4b5 /synapse/handlers/register.py
parentmove handling of auto_join_rooms to RegisterHandler (diff)
parentMerge pull request #3042 from matrix-org/fix_locally_failing_tests (diff)
downloadsynapse-6152e253d842eb4f72be975850450f00c0662e43.tar.xz
Merge branch 'develop' of into allow_auto_join_rooms
Diffstat (limited to 'synapse/handlers/register.py')
-rw-r--r--synapse/handlers/register.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index 88b76278d6..f83c6b3cf8 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -24,7 +24,7 @@ from synapse.api.errors import (
 from synapse.http.client import CaptchaServerHttpClient
 from synapse import types
 from synapse.types import UserID, create_requester, RoomID, RoomAlias
-from synapse.util.async import run_on_reactor
+from synapse.util.async import run_on_reactor, Linearizer
 from synapse.util.threepids import check_3pid_allowed
 from ._base import BaseHandler
 
@@ -46,6 +46,10 @@ class RegistrationHandler(BaseHandler):
 
         self.macaroon_gen = hs.get_macaroon_generator()
 
+        self._generate_user_id_linearizer = Linearizer(
+            name="_generate_user_id_linearizer",
+        )
+
     @defer.inlineCallbacks
     def check_username(self, localpart, guest_access_token=None,
                        assigned_user_id=None):
@@ -352,9 +356,11 @@ class RegistrationHandler(BaseHandler):
     @defer.inlineCallbacks
     def _generate_user_id(self, reseed=False):
         if reseed or self._next_generated_user_id is None:
-            self._next_generated_user_id = (
-                yield self.store.find_next_generated_user_id_localpart()
-            )
+            with (yield self._generate_user_id_linearizer.queue(())):
+                if reseed or self._next_generated_user_id is None:
+                    self._next_generated_user_id = (
+                        yield self.store.find_next_generated_user_id_localpart()
+                    )
 
         id = self._next_generated_user_id
         self._next_generated_user_id += 1