From 722d0be44173d3b137a3bab9a2e5f5e377f9c96f Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 11 Jan 2021 13:32:29 -0500 Subject: [PATCH 1/3] Do not raise errors if non-JSON data is returned. --- synapse/http/matrixfederationclient.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py index b261e078c469..b7103d65415b 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py @@ -174,6 +174,16 @@ async def _handle_json_response( d = timeout_deferred(d, timeout=timeout_sec, reactor=reactor) body = await make_deferred_yieldable(d) + except ValueError as e: + # The JSON content was invalid. + logger.warning( + "{%s} [%s] Failed to parse JSON response - %s %s", + request.txn_id, + request.destination, + request.method, + request.uri.decode("ascii"), + ) + raise RequestSendFailed(e, can_retry=False) from e except defer.TimeoutError as e: logger.warning( "{%s} [%s] Timed out reading response - %s %s", From e7417111b621d09cc1f4604ae025d9ca9cb87896 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 11 Jan 2021 13:38:30 -0500 Subject: [PATCH 2/3] NEwsfragment. --- changelog.d/9070.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9070.bugfix diff --git a/changelog.d/9070.bugfix b/changelog.d/9070.bugfix new file mode 100644 index 000000000000..72b8fe9f1ce9 --- /dev/null +++ b/changelog.d/9070.bugfix @@ -0,0 +1 @@ +Fix `JSONDecodeError` spamming the logs when sending transactions to remote servers. From 90076418dc8cce693ac29bd5bf4dc6e3d3dc3f9c Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 11 Jan 2021 14:00:19 -0500 Subject: [PATCH 3/3] Fix tests. --- tests/http/test_fedclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/http/test_fedclient.py b/tests/http/test_fedclient.py index 212484a7fecb..9c52c8fdca14 100644 --- a/tests/http/test_fedclient.py +++ b/tests/http/test_fedclient.py @@ -560,4 +560,4 @@ def test_json_error(self, return_value): self.pump() f = self.failureResultOf(test_d) - self.assertIsInstance(f.value, ValueError) + self.assertIsInstance(f.value, RequestSendFailed)