summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-07-09 13:01:33 +0100
committerGitHub <noreply@github.com>2020-07-09 13:01:33 +0100
commit8ca39bd2c39b81cc909796c57fe5bca45fcd358c (patch)
tree153a5b488dbe89f37a4202fe265180a0b69a9896
parentFix `can only concatenate list (not "tuple") to list` exception (#7810) (diff)
downloadsynapse-8ca39bd2c39b81cc909796c57fe5bca45fcd358c.tar.xz
Improve stacktraces from exceptions in background processes (#7808)
use `Failure()` to fish out the real exception.
-rw-r--r--changelog.d/7808.misc1
-rw-r--r--synapse/metrics/background_process_metrics.py10
2 files changed, 10 insertions, 1 deletions
diff --git a/changelog.d/7808.misc b/changelog.d/7808.misc
new file mode 100644
index 0000000000..c2acca56ec
--- /dev/null
+++ b/changelog.d/7808.misc
@@ -0,0 +1 @@
+Improve stacktraces from exceptions in background processes.
diff --git a/synapse/metrics/background_process_metrics.py b/synapse/metrics/background_process_metrics.py
index 13785038ad..a9269196b3 100644
--- a/synapse/metrics/background_process_metrics.py
+++ b/synapse/metrics/background_process_metrics.py
@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Set
 from prometheus_client.core import REGISTRY, Counter, Gauge
 
 from twisted.internet import defer
+from twisted.python.failure import Failure
 
 from synapse.logging.context import LoggingContext, PreserveLoggingContext
 
@@ -212,7 +213,14 @@ def run_as_background_process(desc, func, *args, **kwargs):
 
                 return (yield result)
             except Exception:
-                logger.exception("Background process '%s' threw an exception", desc)
+                # failure.Failure() fishes the original Failure out of our stack, and
+                # thus gives us a sensible stack trace.
+                f = Failure()
+                logger.error(
+                    "Background process '%s' threw an exception",
+                    desc,
+                    exc_info=(f.type, f.value, f.getTracebackObject()),
+                )
             finally:
                 _background_process_in_flight_count.labels(desc).dec()