0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-09 03:22:57 +01:00

Merge pull request #1871 from matrix-org/erikj/ratelimit_401

Correctly raise exceptions for ratelimitng. Ratelimit on 401
This commit is contained in:
Erik Johnston 2017-02-01 15:56:16 +00:00 committed by GitHub
commit 96355d2f2f
2 changed files with 6 additions and 4 deletions

View file

@ -504,7 +504,7 @@ class TransactionQueue(object):
code = e.code code = e.code
response = e.response response = e.response
if e.code == 429 or 500 <= e.code: if e.code in (401, 404, 429) or 500 <= e.code:
logger.info( logger.info(
"TX [%s] {%s} got %d response", "TX [%s] {%s} got %d response",
destination, txn_id, code destination, txn_id, code

View file

@ -129,11 +129,13 @@ class RetryDestinationLimiter(object):
# APIs may expect to never received e.g. a 404. It's important to # APIs may expect to never received e.g. a 404. It's important to
# handle 404 as some remote servers will return a 404 when the HS # handle 404 as some remote servers will return a 404 when the HS
# has been decommissioned. # has been decommissioned.
# If we get a 401, then we should probably back off since they
# won't accept our requests for at least a while.
# 429 is us being aggresively rate limited, so lets rate limit
# ourselves.
if exc_val.code == 404 and self.backoff_on_404: if exc_val.code == 404 and self.backoff_on_404:
valid_err_code = False valid_err_code = False
elif exc_val.code == 429: elif exc_val.code in (401, 429):
# 429 is us being aggresively rate limited, so lets rate limit
# ourselves.
valid_err_code = False valid_err_code = False
elif exc_val.code < 500: elif exc_val.code < 500:
valid_err_code = True valid_err_code = True