diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2019-11-06 16:52:54 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2019-11-06 16:52:54 +0000 |
commit | 55bc8d531e0dfe6623d98a9e81ee9a63d1c2799a (patch) | |
tree | 253fb8fcce30d654427cbee2a9199b4715bd8b14 /synapse/handlers/register.py | |
parent | Address review comments (diff) | |
download | synapse-55bc8d531e0dfe6623d98a9e81ee9a63d1c2799a.tar.xz |
raise exception after multiple failures
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/register.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 47b9ae8d7f..235f11c322 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -217,8 +217,13 @@ class RegistrationHandler(BaseHandler): else: # autogen a sequential user ID - # Fail after being unable to find a suitable ID a few times - for x in range(10): + fail_count = 0 + user = None + while not user: + # Fail after being unable to find a suitable ID a few times + if fail_count > 10: + raise SynapseError(500, "Unable to find a suitable guest user ID") + localpart = yield self._generate_user_id() user = UserID(localpart, self.hs.hostname) user_id = user.to_string() @@ -238,7 +243,9 @@ class RegistrationHandler(BaseHandler): break except SynapseError: # if user id is taken, just generate another - pass + user = None + user_id = None + fail_count += 1 if not self.hs.config.user_consent_at_registration: yield self._auto_join_rooms(user_id) |