summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-04-27 12:17:13 +0100
committerRichard van der Hoff <richard@matrix.org>2018-04-27 12:17:13 +0100
commit13843f771ea64cfd4fb7e2f03854b9506f63fcfd (patch)
tree78f87724e1ceed5c0691465042d00a37aa5d77fb
parentMerge pull request #3134 from matrix-org/erikj/fix_admin_media_api (diff)
downloadsynapse-13843f771ea64cfd4fb7e2f03854b9506f63fcfd.tar.xz
Trap exceptions thrown within run_in_background
Turn any exceptions that get thrown synchronously within run_in_background into
Failures instead.
-rw-r--r--synapse/util/logcontext.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py
index d59adc236e..127581a0b4 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -308,7 +308,13 @@ def run_in_background(f, *args, **kwargs):
     on.
     """
     current = LoggingContext.current_context()
-    res = f(*args, **kwargs)
+    try:
+        res = f(*args, **kwargs)
+    except:   # noqa: E722
+        # the assumption here is that the caller doesn't want to be disturbed
+        # by synchronous exceptions, so let's turn them into Failures.
+        return defer.fail()
+
     if isinstance(res, defer.Deferred) and not res.called:
         # The function will have reset the context before returning, so
         # we need to restore it now.