diff options
author | Erik Johnston <erik@matrix.org> | 2020-05-22 11:39:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 11:39:20 +0100 |
commit | 547e4dd83e7d70c30ce8b40578d0750fc10373fa (patch) | |
tree | 84fe85f71ea6e9c5e0794a4659eb8b10ee58733f | |
parent | synapse.metrics: implement detailed memory usage reporting on PyPy (#7536) (diff) | |
download | synapse-547e4dd83e7d70c30ce8b40578d0750fc10373fa.tar.xz |
Fix exception reporting due to HTTP request errors. (#7556)
These are business as usual errors, rather than stuff we want to log at error.
Diffstat (limited to '')
-rw-r--r-- | changelog.d/7556.misc | 1 | ||||
-rw-r--r-- | synapse/app/generic_worker.py | 13 | ||||
-rw-r--r-- | synapse/handlers/federation.py | 7 | ||||
-rw-r--r-- | synapse/http/matrixfederationclient.py | 7 |
4 files changed, 24 insertions, 4 deletions
diff --git a/changelog.d/7556.misc b/changelog.d/7556.misc new file mode 100644 index 0000000000..ed271f9de8 --- /dev/null +++ b/changelog.d/7556.misc @@ -0,0 +1 @@ +Stop logging some expected HTTP request errors as exceptions. diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index d751c9772b..a45c876213 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -26,7 +26,7 @@ from twisted.web.resource import NoResource import synapse import synapse.events -from synapse.api.errors import SynapseError +from synapse.api.errors import HttpResponseException, RequestSendFailed, SynapseError from synapse.api.urls import ( CLIENT_API_PREFIX, FEDERATION_PREFIX, @@ -202,9 +202,14 @@ class KeyUploadServlet(RestServlet): # is there. auth_headers = request.requestHeaders.getRawHeaders(b"Authorization", []) headers = {"Authorization": auth_headers} - result = await self.http_client.post_json_get_json( - self.main_uri + request.uri.decode("ascii"), body, headers=headers - ) + try: + result = await self.http_client.post_json_get_json( + self.main_uri + request.uri.decode("ascii"), body, headers=headers + ) + except HttpResponseException as e: + raise e.to_synapse() from e + except RequestSendFailed as e: + raise SynapseError(502, "Failed to talk to master") from e return 200, result else: diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 81d859f807..bb03cc9add 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -40,6 +40,7 @@ from synapse.api.errors import ( Codes, FederationDeniedError, FederationError, + HttpResponseException, RequestSendFailed, SynapseError, ) @@ -1038,6 +1039,12 @@ class FederationHandler(BaseHandler): except SynapseError as e: logger.info("Failed to backfill from %s because %s", dom, e) continue + except HttpResponseException as e: + if 400 <= e.code < 500: + raise e.to_synapse_error() + + logger.info("Failed to backfill from %s because %s", dom, e) + continue except CodeMessageException as e: if 400 <= e.code < 500: raise diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py index 44077f5349..2d47b9ea00 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py @@ -144,6 +144,11 @@ def _handle_json_response(reactor, timeout_sec, request, response): d = timeout_deferred(d, timeout=timeout_sec, reactor=reactor) body = yield make_deferred_yieldable(d) + except TimeoutError as e: + logger.warning( + "{%s} [%s] Timed out reading response", request.txn_id, request.destination, + ) + raise RequestSendFailed(e, can_retry=True) from e except Exception as e: logger.warning( "{%s} [%s] Error reading response: %s", @@ -424,6 +429,8 @@ class MatrixFederationHttpClient(object): ) response = yield request_deferred + except TimeoutError as e: + raise RequestSendFailed(e, can_retry=True) from e except DNSLookupError as e: raise_from(RequestSendFailed(e, can_retry=retry_on_dns_fail), e) except Exception as e: |