forked-synapse/synapse
Sean Quah 14b8c0476f
Prevent logging context going missing on federation request timeout (#10810)
In `MatrixFederationHttpClient._send_request()`, we make a HTTP request
using an `Agent`, wrap that request in a timeout and await the resulting
`Deferred`. On its own, the `Agent` performing the HTTP request
correctly stashes and restores the logging context while waiting.
The addition of the timeout introduces a path where the logging context
is not restored when execution resumes.

To address this, we wrap the timeout `Deferred` in a
`make_deferred_yieldable()` to stash the logging context and restore it
on completion of the `await`. However this is not sufficient, since by
the time we construct the timeout `Deferred`, the `Agent` has already
stashed and cleared the logging context when using
`make_deferred_yieldable()` to produce its `Deferred` for the request.

Hence, we wrap the `Agent` request in a `run_in_background()` to "fork"
and preserve the logging context so that we can stash and restore it
when `await`ing the timeout `Deferred`.

This approach is similar to the one used with `defer.gatherResults`.

Note that the code is still not fully correct. When a timeout occurs,
the request remains running in the background (existing behavior which
is nothing to do with the new call to `run_in_background`) and may
re-start the logging context after it has finished.
2021-09-14 13:01:30 +01:00
..
_scripts Remove shebang line from module files (#10415) 2021-07-29 21:34:14 +01:00
api Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
app Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
appservice Use inline type hints in various other places (in synapse/) (#10380) 2021-07-15 11:02:43 +01:00
config Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
crypto Use inline type hints in various other places (in synapse/) (#10380) 2021-07-15 11:02:43 +01:00
events Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
federation Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
groups Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
handlers Name the type of token in "Invalid token" messages (#10815) 2021-09-14 11:25:05 +01:00
http Prevent logging context going missing on federation request timeout (#10810) 2021-09-14 13:01:30 +01:00
logging Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
metrics [pyupgrade] synapse/ (#10348) 2021-07-19 15:28:05 +01:00
module_api Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
push Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
replication Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
res Allow configuration of the oEmbed URLs. (#10714) 2021-08-31 18:37:07 -04:00
rest Convert media repo's FileInfo to attrs. (#10785) 2021-09-14 07:09:38 -04:00
server_notices Improve ServerNoticeServlet to avoid duplicate requests (#10679) 2021-08-27 09:16:40 +00:00
spam_checker_api Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
state Add type hints to state handler. (#10482) 2021-07-26 12:49:53 -04:00
static Display an error page during failure of fallback UIA. (#10561) 2021-08-18 08:13:35 -04:00
storage Name the type of token in "Invalid token" messages (#10815) 2021-09-14 11:25:05 +01:00
streams Add a return type to parse_string. (#10438) 2021-07-21 09:47:56 -04:00
util Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
__init__.py 1.43.0rc1 2021-09-14 11:47:11 +01:00
event_auth.py Add a constant for m.federate. (#10775) 2021-09-08 10:00:43 -04:00
notifier.py Generics for ObservableDeferred (#10491) 2021-07-28 19:55:50 +00:00
python_dependencies.py Validate new m.room.power_levels events (#10232) 2021-08-26 17:07:58 +01:00
server.py Use direct references for some configuration variables (#10798) 2021-09-13 13:07:12 -04:00
types.py Name the type of token in "Invalid token" messages (#10815) 2021-09-14 11:25:05 +01:00
visibility.py [pyupgrade] synapse/ (#10348) 2021-07-19 15:28:05 +01:00