diff options
author | Richard van der Hoff <richard@matrix.org> | 2019-01-30 10:07:33 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2019-01-30 10:58:52 +0000 |
commit | 928c50b59aa4cf280748b484d76d5a967adc159e (patch) | |
tree | e45498eae8dc32cd425f85b42768ec1efb84af63 /synapse/http/federation/matrix_federation_agent.py | |
parent | Add a caching layer to .well-known responses (#4516) (diff) | |
download | synapse-928c50b59aa4cf280748b484d76d5a967adc159e.tar.xz |
Also jitter the invalid cache period
Diffstat (limited to 'synapse/http/federation/matrix_federation_agent.py')
-rw-r--r-- | synapse/http/federation/matrix_federation_agent.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py index 29804efe10..e4226b5c31 100644 --- a/synapse/http/federation/matrix_federation_agent.py +++ b/synapse/http/federation/matrix_federation_agent.py @@ -296,16 +296,18 @@ class MatrixFederationAgent(object): response = yield make_deferred_yieldable( self._well_known_agent.request(b"GET", uri), ) + body = yield make_deferred_yieldable(readBody(response)) + if response.code != 200: + raise Exception("Non-200 response %s", response.code) except Exception as e: - logger.info("Connection error fetching %s: %s", uri_str, e) - self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD) - defer.returnValue(None) + logger.info("Error fetching %s: %s", uri_str, e) - body = yield make_deferred_yieldable(readBody(response)) + # add some randomness to the TTL to avoid a stampeding herd every hour + # after startup + cache_period = WELL_KNOWN_INVALID_CACHE_PERIOD + cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER) - if response.code != 200: - logger.info("Error response %i from %s", response.code, uri_str) - self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD) + self._well_known_cache.set(server_name, None, cache_period) defer.returnValue(None) try: @@ -326,8 +328,8 @@ class MatrixFederationAgent(object): ) if cache_period is None: cache_period = WELL_KNOWN_DEFAULT_CACHE_PERIOD - # add some randomness to the TTL to avoid a stampeding herd every hour after - # startup + # add some randomness to the TTL to avoid a stampeding herd every 24 hours + # after startup cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER) else: cache_period = min(cache_period, WELL_KNOWN_MAX_CACHE_PERIOD) |