Skip to content

Commit 4b9441e

Browse files
committed
Transparent deferred callback/errback when we _set_context_cb
1 parent 33776c0 commit 4b9441e

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

synapse/logging/context.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from typing_extensions import ParamSpec
5353

5454
from twisted.internet import defer, threads
55+
from twisted.python.failure import Failure
5556
from twisted.python.threadpool import ThreadPool
5657

5758
from synapse.logging.loggers import ExplicitlyConfiguredLogger
@@ -963,6 +964,12 @@ def _log_set_context_cb(
963964
context,
964965
)
965966
set_current_context(context)
967+
968+
# Re-raise the exception so that any further errbacks can do their thing as
969+
# normal
970+
if isinstance(result, Failure):
971+
result.raiseException()
972+
# Otherwise, pass the result through
966973
return result
967974

968975
d.addBoth(_log_set_context_cb, SENTINEL_CONTEXT)
@@ -1069,6 +1076,12 @@ def _log_set_context_cb(
10691076
context,
10701077
)
10711078
set_current_context(context)
1079+
1080+
# Re-raise the exception so that any further errbacks can do their thing as
1081+
# normal
1082+
if isinstance(result, Failure):
1083+
result.raiseException()
1084+
# Otherwise, pass the result through
10721085
return result
10731086

10741087
deferred.addBoth(_log_set_context_cb, calling_context)
@@ -1082,8 +1095,17 @@ def _log_set_context_cb(
10821095

10831096

10841097
def _set_context_cb(result: ResultT, context: LoggingContextOrSentinel) -> ResultT:
1085-
"""A callback function which just sets the logging context"""
1098+
"""
1099+
A transparent passthrough deferred callback/errback which sets the logging context
1100+
"""
10861101
set_current_context(context)
1102+
1103+
# Re-raise the exception so that any further errbacks can do their thing as
1104+
# normal
1105+
if isinstance(result, Failure):
1106+
result.raiseException()
1107+
1108+
# Otherwise, pass the result through
10871109
return result
10881110

10891111

0 commit comments

Comments
 (0)