summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-03-26 12:02:20 +0100
committerErik Johnston <erik@matrix.org>2018-03-26 12:02:20 +0100
commita052aa42e7d500f32b034bbbf1e8ad11fed02aa9 (patch)
tree48336582984242125fc52b1738f241f6354d6286 /synapse/handlers
parentMerge pull request #3006 from matrix-org/erikj/state_iter (diff)
downloadsynapse-a052aa42e7d500f32b034bbbf1e8ad11fed02aa9.tar.xz
Linearize calls to _generate_user_id
Diffstat (limited to '')
-rw-r--r--synapse/handlers/register.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index ed5939880a..d07a8801de 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
-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,8 @@ 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):
@@ -345,9 +347,10 @@ 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(())):
+                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