Fix a number of logged errors caused by remote servers being down. (#10400)

This commit is contained in:
Erik Johnston 2021-07-15 10:35:46 +01:00 committed by GitHub
parent 0ae95b3847
commit 7695ca0618
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 19 deletions

1
changelog.d/10400.bugfix Normal file
View file

@ -0,0 +1 @@
Fix a number of logged errors caused by remote servers being down.

View file

@ -22,6 +22,7 @@ from synapse.api.errors import (
CodeMessageException, CodeMessageException,
Codes, Codes,
NotFoundError, NotFoundError,
RequestSendFailed,
ShadowBanError, ShadowBanError,
StoreError, StoreError,
SynapseError, SynapseError,
@ -252,12 +253,14 @@ class DirectoryHandler(BaseHandler):
retry_on_dns_fail=False, retry_on_dns_fail=False,
ignore_backoff=True, ignore_backoff=True,
) )
except RequestSendFailed:
raise SynapseError(502, "Failed to fetch alias")
except CodeMessageException as e: except CodeMessageException as e:
logging.warning("Error retrieving alias") logging.warning("Error retrieving alias")
if e.code == 404: if e.code == 404:
fed_result = None fed_result = None
else: else:
raise raise SynapseError(502, "Failed to fetch alias")
if fed_result and "room_id" in fed_result and "servers" in fed_result: if fed_result and "room_id" in fed_result and "servers" in fed_result:
room_id = fed_result["room_id"] room_id = fed_result["room_id"]

View file

@ -1414,12 +1414,15 @@ class FederationHandler(BaseHandler):
Invites must be signed by the invitee's server before distribution. Invites must be signed by the invitee's server before distribution.
""" """
pdu = await self.federation_client.send_invite( try:
destination=target_host, pdu = await self.federation_client.send_invite(
room_id=event.room_id, destination=target_host,
event_id=event.event_id, room_id=event.room_id,
pdu=event, event_id=event.event_id,
) pdu=event,
)
except RequestSendFailed:
raise SynapseError(502, f"Can't connect to server {target_host}")
return pdu return pdu
@ -3031,9 +3034,13 @@ class FederationHandler(BaseHandler):
await member_handler.send_membership_event(None, event, context) await member_handler.send_membership_event(None, event, context)
else: else:
destinations = {x.split(":", 1)[-1] for x in (sender_user_id, room_id)} destinations = {x.split(":", 1)[-1] for x in (sender_user_id, room_id)}
await self.federation_client.forward_third_party_invite(
destinations, room_id, event_dict try:
) await self.federation_client.forward_third_party_invite(
destinations, room_id, event_dict
)
except (RequestSendFailed, HttpResponseException):
raise SynapseError(502, "Failed to forward third party invite")
async def on_exchange_third_party_invite_request( async def on_exchange_third_party_invite_request(
self, event_dict: JsonDict self, event_dict: JsonDict

View file

@ -20,7 +20,12 @@ import msgpack
from unpaddedbase64 import decode_base64, encode_base64 from unpaddedbase64 import decode_base64, encode_base64
from synapse.api.constants import EventTypes, HistoryVisibility, JoinRules from synapse.api.constants import EventTypes, HistoryVisibility, JoinRules
from synapse.api.errors import Codes, HttpResponseException from synapse.api.errors import (
Codes,
HttpResponseException,
RequestSendFailed,
SynapseError,
)
from synapse.types import JsonDict, ThirdPartyInstanceID from synapse.types import JsonDict, ThirdPartyInstanceID
from synapse.util.caches.descriptors import cached from synapse.util.caches.descriptors import cached
from synapse.util.caches.response_cache import ResponseCache from synapse.util.caches.response_cache import ResponseCache
@ -417,14 +422,17 @@ class RoomListHandler(BaseHandler):
repl_layer = self.hs.get_federation_client() repl_layer = self.hs.get_federation_client()
if search_filter: if search_filter:
# We can't cache when asking for search # We can't cache when asking for search
return await repl_layer.get_public_rooms( try:
server_name, return await repl_layer.get_public_rooms(
limit=limit, server_name,
since_token=since_token, limit=limit,
search_filter=search_filter, since_token=since_token,
include_all_networks=include_all_networks, search_filter=search_filter,
third_party_instance_id=third_party_instance_id, include_all_networks=include_all_networks,
) third_party_instance_id=third_party_instance_id,
)
except (RequestSendFailed, HttpResponseException):
raise SynapseError(502, "Failed to fetch room list")
key = ( key = (
server_name, server_name,

View file

@ -43,6 +43,7 @@ from twisted.internet import defer
from twisted.internet.error import DNSLookupError from twisted.internet.error import DNSLookupError
from twisted.internet.interfaces import IReactorTime from twisted.internet.interfaces import IReactorTime
from twisted.internet.task import _EPSILON, Cooperator from twisted.internet.task import _EPSILON, Cooperator
from twisted.web.client import ResponseFailed
from twisted.web.http_headers import Headers from twisted.web.http_headers import Headers
from twisted.web.iweb import IBodyProducer, IResponse from twisted.web.iweb import IBodyProducer, IResponse
@ -262,6 +263,15 @@ async def _handle_response(
request.uri.decode("ascii"), request.uri.decode("ascii"),
) )
raise RequestSendFailed(e, can_retry=True) from e raise RequestSendFailed(e, can_retry=True) from e
except ResponseFailed as e:
logger.warning(
"{%s} [%s] Failed to read response - %s %s",
request.txn_id,
request.destination,
request.method,
request.uri.decode("ascii"),
)
raise RequestSendFailed(e, can_retry=True) from e
except Exception as e: except Exception as e:
logger.warning( logger.warning(
"{%s} [%s] Error reading response %s %s: %s", "{%s} [%s] Error reading response %s %s: %s",
@ -1137,6 +1147,24 @@ class MatrixFederationHttpClient:
msg, msg,
) )
raise SynapseError(502, msg, Codes.TOO_LARGE) raise SynapseError(502, msg, Codes.TOO_LARGE)
except defer.TimeoutError as e:
logger.warning(
"{%s} [%s] Timed out reading response - %s %s",
request.txn_id,
request.destination,
request.method,
request.uri.decode("ascii"),
)
raise RequestSendFailed(e, can_retry=True) from e
except ResponseFailed as e:
logger.warning(
"{%s} [%s] Failed to read response - %s %s",
request.txn_id,
request.destination,
request.method,
request.uri.decode("ascii"),
)
raise RequestSendFailed(e, can_retry=True) from e
except Exception as e: except Exception as e:
logger.warning( logger.warning(
"{%s} [%s] Error reading response: %s", "{%s} [%s] Error reading response: %s",