From 4548e5afea0074a32486519ed9512b96ea88df72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20S=C3=B8borg?= Date: Thu, 22 Oct 2020 23:49:04 +0200 Subject: [PATCH 1/3] Catch exceptions in password_providers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolai Søborg --- changelog.d/8636.misc | 1 + synapse/handlers/auth.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelog.d/8636.misc diff --git a/changelog.d/8636.misc b/changelog.d/8636.misc new file mode 100644 index 000000000000..df4dca42f8ba --- /dev/null +++ b/changelog.d/8636.misc @@ -0,0 +1 @@ +Catch exceptions during initialization of `password_providers`. Contributed by Nicolai Søborg. diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 8619fbb982f6..6a0e4a866453 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -172,10 +172,14 @@ def __init__(self, hs): # better way to break the loop account_handler = ModuleApi(hs, self) - self.password_providers = [ - module(config=config, account_handler=account_handler) - for module, config in hs.config.password_providers - ] + self.password_providers = [] + for module, config in hs.config.password_providers: + try: + self.password_providers.append( + module(config=config, account_handler=account_handler) + ) + except Exception as e: + logger.warn("Error while initializing %r: %s", module, e) logger.info("Extra password_providers: %r", self.password_providers) From 191147be81be41cfc56a16d4bb4241499452849a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20S=C3=B8borg?= Date: Fri, 30 Oct 2020 20:10:53 +0000 Subject: [PATCH 2/3] Re-raise exception This will make sure that synapse will not start if any `password_provider` throws in `__init__` --- synapse/handlers/auth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 6a0e4a866453..2b0ee26a6794 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -180,6 +180,7 @@ def __init__(self, hs): ) except Exception as e: logger.warn("Error while initializing %r: %s", module, e) + raise logger.info("Extra password_providers: %r", self.password_providers) From 662b5ad67e92cb872033f1e60b518a8bbf7d11a6 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 6 Nov 2020 11:33:37 +0000 Subject: [PATCH 3/3] Log as error --- synapse/handlers/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 2b0ee26a6794..63820fc82c81 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -179,7 +179,7 @@ def __init__(self, hs): module(config=config, account_handler=account_handler) ) except Exception as e: - logger.warn("Error while initializing %r: %s", module, e) + logger.error("Error while initializing %r: %s", module, e) raise logger.info("Extra password_providers: %r", self.password_providers)