diff options
author | Erik Johnston <erikj@jki.re> | 2018-03-28 10:00:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 10:00:31 +0100 |
commit | f879127aaa41ff95bbd5c1501b6f11c8eb3373d3 (patch) | |
tree | 86827b229ba0de82bb1a082349ee547e779e9863 /synapse/handlers | |
parent | Merge pull request #3030 from matrix-org/erikj/no_ujson (diff) | |
parent | Also do check inside linearizer (diff) | |
download | synapse-f879127aaa41ff95bbd5c1501b6f11c8eb3373d3.tar.xz |
Merge pull request #3029 from matrix-org/erikj/linearize_generate_user_id
Linearize calls to _generate_user_id
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/register.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index ed5939880a..dd03705279 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,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): @@ -345,9 +349,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 |