summary refs log tree commit diff
path: root/synapse/util/logcontext.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-04-30 10:23:02 +0100
committerGitHub <noreply@github.com>2018-04-30 10:23:02 +0100
commitfdb6849b818e21be028578f1ab20a5e24c1152a5 (patch)
tree03abd6e02884c61c5cab82176204f0df7f280830 /synapse/util/logcontext.py
parentMerge pull request #3159 from NotAFile/py3-tests-config (diff)
parentTrap exceptions thrown within run_in_background (diff)
downloadsynapse-fdb6849b818e21be028578f1ab20a5e24c1152a5.tar.xz
Merge pull request #3144 from matrix-org/rav/run_in_background_exception_handling
Trap exceptions thrown within run_in_background
Diffstat (limited to 'synapse/util/logcontext.py')
-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 bbadeec922..01ac71e53e 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -313,7 +313,13 @@ def run_in_background(f, *args, **kwargs):
     indication about where it came from.
     """
     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.