From 2bc02893c879d742095eb937b81e681612d22e13 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 23 Feb 2022 13:24:46 -0500 Subject: [PATCH 1/4] Fix typos. --- synapse/federation/federation_client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 2121e92e3a9f..afd7e4a4d099 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -1002,7 +1002,7 @@ async def _do_send_join( ) except HttpResponseException as e: # If an error is received that is due to an unrecognised endpoint, - # fallback to the v1 endpoint. Otherwise consider it a legitmate error + # fallback to the v1 endpoint. Otherwise, consider it a legitimate error # and raise. if not self._is_unknown_endpoint(e): raise @@ -1071,7 +1071,7 @@ async def _do_send_invite( except HttpResponseException as e: # If an error is received that is due to an unrecognised endpoint, # fallback to the v1 endpoint if the room uses old-style event IDs. - # Otherwise consider it a legitmate error and raise. + # Otherwise, consider it a legitimate error and raise. err = e.to_synapse_error() if self._is_unknown_endpoint(e, err): if room_version.event_format != EventFormatVersions.V1: @@ -1132,7 +1132,7 @@ async def _do_send_leave(self, destination: str, pdu: EventBase) -> JsonDict: ) except HttpResponseException as e: # If an error is received that is due to an unrecognised endpoint, - # fallback to the v1 endpoint. Otherwise consider it a legitmate error + # fallback to the v1 endpoint. Otherwise, consider it a legitimate error # and raise. if not self._is_unknown_endpoint(e): raise @@ -1458,8 +1458,8 @@ async def send_request( ) except HttpResponseException as e: # If an error is received that is due to an unrecognised endpoint, - # fallback to the unstable endpoint. Otherwise consider it a - # legitmate error and raise. + # fallback to the unstable endpoint. Otherwise, consider it a + # legitimate error and raise. if not self._is_unknown_endpoint(e): raise From c04e499d1def179235a95c3be20b8fdf6c3f3d8c Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 23 Feb 2022 13:32:47 -0500 Subject: [PATCH 2/4] Only consider empty responses to be unknown endpoints. --- synapse/federation/federation_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index afd7e4a4d099..635fa5b00d6d 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -617,7 +617,7 @@ def _is_unknown_endpoint( # # Dendrite returns a 404 (with no body); synapse returns a 400 # with M_UNRECOGNISED. - return e.code == 404 or ( + return (e.code == 404 and not e.response) or ( e.code == 400 and synapse_error.errcode == Codes.UNRECOGNIZED ) From c8255cc11776086220c8683159acd05f8bfd0410 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 23 Feb 2022 14:24:27 -0500 Subject: [PATCH 3/4] Fix support for Dendrite's unknown endpoints. --- synapse/federation/federation_client.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py index 635fa5b00d6d..a4bae3c4c85f 100644 --- a/synapse/federation/federation_client.py +++ b/synapse/federation/federation_client.py @@ -615,11 +615,15 @@ def _is_unknown_endpoint( synapse_error = e.to_synapse_error() # There is no good way to detect an "unknown" endpoint. # - # Dendrite returns a 404 (with no body); synapse returns a 400 + # Dendrite returns a 404 (with a body of "404 page not found"); + # Conduit returns a 404 (with no body); and Synapse returns a 400 # with M_UNRECOGNISED. - return (e.code == 404 and not e.response) or ( - e.code == 400 and synapse_error.errcode == Codes.UNRECOGNIZED - ) + # + # This needs to be rather specific as some endpoints truly do return 404 + # errors. + return ( + e.code == 404 and (not e.response or e.response == b"404 page not found") + ) or (e.code == 400 and synapse_error.errcode == Codes.UNRECOGNIZED) async def _try_destination_list( self, From c64c4dea23a2f7006daa559828258665b23dcb4a Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 24 Feb 2022 11:39:06 -0500 Subject: [PATCH 4/4] Newsfragment --- changelog.d/12077.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12077.bugfix diff --git a/changelog.d/12077.bugfix b/changelog.d/12077.bugfix new file mode 100644 index 000000000000..1bce82082dad --- /dev/null +++ b/changelog.d/12077.bugfix @@ -0,0 +1 @@ +Fix a long-standing bug where Synapse would make additional failing requests over federation for missing data.