Skip to content
Snippets Groups Projects
Unverified Commit 8ca39bd2 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Improve stacktraces from exceptions in background processes (#7808)

use `Failure()` to fish out the real exception.
parent 08c5181a
No related branches found
No related tags found
No related merge requests found
Improve stacktraces from exceptions in background processes.
...@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Set ...@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Set
from prometheus_client.core import REGISTRY, Counter, Gauge from prometheus_client.core import REGISTRY, Counter, Gauge
from twisted.internet import defer from twisted.internet import defer
from twisted.python.failure import Failure
from synapse.logging.context import LoggingContext, PreserveLoggingContext from synapse.logging.context import LoggingContext, PreserveLoggingContext
...@@ -212,7 +213,14 @@ def run_as_background_process(desc, func, *args, **kwargs): ...@@ -212,7 +213,14 @@ def run_as_background_process(desc, func, *args, **kwargs):
return (yield result) return (yield result)
except Exception: 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: finally:
_background_process_in_flight_count.labels(desc).dec() _background_process_in_flight_count.labels(desc).dec()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment