4747from synapse .logging .context import (
4848 ContextResourceUsage ,
4949 LoggingContext ,
50- make_deferred_yieldable ,
50+ PreserveLoggingContext ,
5151)
5252from synapse .logging .opentracing import SynapseTags , start_active_span
5353from synapse .metrics import SERVER_NAME_LABEL
@@ -223,9 +223,10 @@ def run_as_background_process(
223223 This should be used to wrap processes which are fired off to run in the
224224 background, instead of being associated with a particular request.
225225
226- It returns a Deferred which completes when the function completes, which makes it
227- appropriate for passing to clock.looping_call and friends (or for
228- firing-and-forgetting in the middle of a normal synapse async function).
226+ It returns a Deferred which completes when the function completes, but it doesn't
227+ follow the synapse logcontext rules, which makes it appropriate for passing to
228+ clock.looping_call and friends (or for firing-and-forgetting in the middle of a
229+ normal synapse async function).
229230
230231 Args:
231232 desc: a description for this background process type
@@ -240,6 +241,8 @@ def run_as_background_process(
240241
241242 Returns:
242243 Deferred which returns the result of func, or `None` if func raises.
244+ Note that the returned Deferred does not follow the synapse logcontext
245+ rules.
243246 """
244247
245248 async def run () -> Optional [R ]:
@@ -277,9 +280,10 @@ async def run() -> Optional[R]:
277280 name = desc , ** {SERVER_NAME_LABEL : server_name }
278281 ).dec ()
279282
283+ with PreserveLoggingContext ():
280284 # Note that we return a Deferred here so that it can be used in a
281285 # looping_call and other places that expect a Deferred.
282- return make_deferred_yieldable ( defer .ensureDeferred (run () ))
286+ return defer .ensureDeferred (run ())
283287
284288
285289P = ParamSpec ("P" )
0 commit comments