forked-synapse/synapse/http
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
..
federation Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
__init__.py Use inline type hints in various other places (in synapse/) (#10380) 2021-07-15 11:02:43 +01:00
additional_resource.py Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
client.py Fix up type hints for Twisted 21.7 (#10490) 2021-07-28 12:04:11 +00:00
connectproxyclient.py support federation queries through http connect proxy (#10475) 2021-08-11 15:34:59 +01:00
matrixfederationclient.py Prevent logging context going missing on federation request timeout (#10810) 2021-09-14 13:01:30 +01:00
proxyagent.py Additional type hints for the proxy agent and SRV resolver modules. (#10608) 2021-08-18 13:53:20 -04:00
request_metrics.py Remove redundant "coding: utf-8" lines (#9786) 2021-04-14 15:34:27 +01:00
server.py Use inline type hints in various other places (in synapse/) (#10380) 2021-07-15 11:02:43 +01:00
servlet.py Additional type hints for client REST servlets (part 5) (#10736) 2021-09-03 09:22:22 -04:00
site.py Change logging of puppeted requests to better differentiate users (#10779) 2021-09-08 12:59:15 +00:00