From 928c50b59aa4cf280748b484d76d5a967adc159e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 30 Jan 2019 10:07:33 +0000 Subject: [PATCH 1/3] Also jitter the invalid cache period --- .../federation/matrix_federation_agent.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py index 29804efe1059..e4226b5c3193 100644 --- a/synapse/http/federation/matrix_federation_agent.py +++ b/synapse/http/federation/matrix_federation_agent.py @@ -296,16 +296,18 @@ def _get_well_known(self, server_name): 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 @@ def _get_well_known(self, server_name): ) 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) From 09a1a6b55e0d31c3c91370c3605ec9e420ec8d0b Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 30 Jan 2019 10:14:11 +0000 Subject: [PATCH 2/3] fix exception text --- synapse/http/federation/matrix_federation_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py index e4226b5c3193..fd298d83f4df 100644 --- a/synapse/http/federation/matrix_federation_agent.py +++ b/synapse/http/federation/matrix_federation_agent.py @@ -298,7 +298,7 @@ def _get_well_known(self, server_name): ) body = yield make_deferred_yieldable(readBody(response)) if response.code != 200: - raise Exception("Non-200 response %s", response.code) + raise Exception("Non-200 response %s" % (response.code, )) except Exception as e: logger.info("Error fetching %s: %s", uri_str, e) From 283753c33a19a5985354966b018572b80c31a017 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 30 Jan 2019 10:59:21 +0000 Subject: [PATCH 3/3] newsfile --- changelog.d/4521.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4521.feature diff --git a/changelog.d/4521.feature b/changelog.d/4521.feature new file mode 100644 index 000000000000..bda713adf913 --- /dev/null +++ b/changelog.d/4521.feature @@ -0,0 +1 @@ +Implement MSC1708 (.well-known routing for server-server federation) \ No newline at end of file