Merge pull request #5385 from matrix-org/erikj/reduce_http_exceptions

Handle HttpResponseException when using federation client.
This commit is contained in:
Erik Johnston 2019-06-17 13:54:47 +01:00 committed by GitHub
commit 6840ebeef8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 19 deletions

1
changelog.d/5383.misc Normal file
View File

@ -0,0 +1 @@
Don't log non-200 responses from federation queries as exceptions.

View File

@ -42,7 +42,7 @@ from signedjson.sign import sign_json
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import RequestSendFailed, SynapseError from synapse.api.errors import HttpResponseException, RequestSendFailed, SynapseError
from synapse.metrics.background_process_metrics import run_as_background_process from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.types import get_domain_from_id from synapse.types import get_domain_from_id
from synapse.util.logcontext import run_in_background from synapse.util.logcontext import run_in_background
@ -195,7 +195,7 @@ class GroupAttestionRenewer(object):
yield self.store.update_attestation_renewal( yield self.store.update_attestation_renewal(
group_id, user_id, attestation group_id, user_id, attestation
) )
except RequestSendFailed as e: except (RequestSendFailed, HttpResponseException) as e:
logger.warning( logger.warning(
"Failed to renew attestation of %r in %r: %s", "Failed to renew attestation of %r in %r: %s",
user_id, group_id, e, user_id, group_id, e,

View File

@ -49,9 +49,7 @@ def _create_rerouter(func_name):
def http_response_errback(failure): def http_response_errback(failure):
failure.trap(HttpResponseException) failure.trap(HttpResponseException)
e = failure.value e = failure.value
if e.code == 403: raise e.to_synapse_error()
raise e.to_synapse_error()
return failure
def request_failed_errback(failure): def request_failed_errback(failure):
failure.trap(RequestSendFailed) failure.trap(RequestSendFailed)

View File

@ -15,12 +15,15 @@
import logging import logging
from six import raise_from
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import ( from synapse.api.errors import (
AuthError, AuthError,
CodeMessageException,
Codes, Codes,
HttpResponseException,
RequestSendFailed,
StoreError, StoreError,
SynapseError, SynapseError,
) )
@ -85,10 +88,10 @@ class BaseProfileHandler(BaseHandler):
ignore_backoff=True, ignore_backoff=True,
) )
defer.returnValue(result) defer.returnValue(result)
except CodeMessageException as e: except RequestSendFailed as e:
if e.code != 404: raise_from(SynapseError(502, "Failed to fetch profile"), e)
logger.exception("Failed to get displayname") except HttpResponseException as e:
raise raise e.to_synapse_error()
@defer.inlineCallbacks @defer.inlineCallbacks
def get_profile_from_cache(self, user_id): def get_profile_from_cache(self, user_id):
@ -142,10 +145,10 @@ class BaseProfileHandler(BaseHandler):
}, },
ignore_backoff=True, ignore_backoff=True,
) )
except CodeMessageException as e: except RequestSendFailed as e:
if e.code != 404: raise_from(SynapseError(502, "Failed to fetch profile"), e)
logger.exception("Failed to get displayname") except HttpResponseException as e:
raise raise e.to_synapse_error()
defer.returnValue(result["displayname"]) defer.returnValue(result["displayname"])
@ -208,10 +211,10 @@ class BaseProfileHandler(BaseHandler):
}, },
ignore_backoff=True, ignore_backoff=True,
) )
except CodeMessageException as e: except RequestSendFailed as e:
if e.code != 404: raise_from(SynapseError(502, "Failed to fetch profile"), e)
logger.exception("Failed to get avatar_url") except HttpResponseException as e:
raise raise e.to_synapse_error()
defer.returnValue(result["avatar_url"]) defer.returnValue(result["avatar_url"])

View File

@ -17,11 +17,17 @@ import abc
import logging import logging
import re import re
from six import raise_from
from six.moves import urllib from six.moves import urllib
from twisted.internet import defer from twisted.internet import defer
from synapse.api.errors import CodeMessageException, HttpResponseException from synapse.api.errors import (
CodeMessageException,
HttpResponseException,
RequestSendFailed,
SynapseError,
)
from synapse.util.caches.response_cache import ResponseCache from synapse.util.caches.response_cache import ResponseCache
from synapse.util.stringutils import random_string from synapse.util.stringutils import random_string
@ -175,6 +181,8 @@ class ReplicationEndpoint(object):
# on the master process that we should send to the client. (And # on the master process that we should send to the client. (And
# importantly, not stack traces everywhere) # importantly, not stack traces everywhere)
raise e.to_synapse_error() raise e.to_synapse_error()
except RequestSendFailed as e:
raise_from(SynapseError(502, "Failed to talk to master"), e)
defer.returnValue(result) defer.returnValue(result)