diff options
author | Erik Johnston <erik@matrix.org> | 2018-03-01 16:26:42 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2018-03-01 16:26:42 +0000 |
commit | 64346be26de92860b7c2b22edc3ffa740beee3d0 (patch) | |
tree | dfc78650bd630bb06dcd64e9178f06d2e9fbcd84 /synapse/util/logcontext.py | |
parent | Remove unused variables (diff) | |
parent | Merge pull request #2923 from matrix-org/erikj/stream_ago_worker (diff) | |
download | synapse-64346be26de92860b7c2b22edc3ffa740beee3d0.tar.xz |
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/split_stream_store
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r-- | synapse/util/logcontext.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py index 94fa7cac98..a8dea15c1b 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py @@ -299,10 +299,6 @@ def preserve_fn(f): Useful for wrapping functions that return a deferred which you don't yield on. """ - def reset_context(result): - LoggingContext.set_current_context(LoggingContext.sentinel) - return result - def g(*args, **kwargs): current = LoggingContext.current_context() res = f(*args, **kwargs) @@ -323,12 +319,11 @@ def preserve_fn(f): # which is supposed to have a single entry and exit point. But # by spawning off another deferred, we are effectively # adding a new exit point.) - res.addBoth(reset_context) + res.addBoth(_set_context_cb, LoggingContext.sentinel) return res return g -@defer.inlineCallbacks def make_deferred_yieldable(deferred): """Given a deferred, make it follow the Synapse logcontext rules: @@ -342,9 +337,16 @@ def make_deferred_yieldable(deferred): (This is more-or-less the opposite operation to preserve_fn.) """ - with PreserveLoggingContext(): - r = yield deferred - defer.returnValue(r) + if isinstance(deferred, defer.Deferred) and not deferred.called: + prev_context = LoggingContext.set_current_context(LoggingContext.sentinel) + deferred.addBoth(_set_context_cb, prev_context) + return deferred + + +def _set_context_cb(result, context): + """A callback function which just sets the logging context""" + LoggingContext.set_current_context(context) + return result # modules to ignore in `logcontext_tracer` |