diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py index 6b0d2deea0..6a7be324a6 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py @@ -22,6 +22,7 @@ them. See doc/log_contexts.rst for details on how this works. """ +import types import logging import threading @@ -544,6 +545,9 @@ def run_in_background(f, *args, **kwargs): # by synchronous exceptions, so let's turn them into Failures. return defer.fail() + if isinstance(res, types.CoroutineType): + res = defer.ensureDeferred(res) + if not isinstance(res, defer.Deferred): return res