Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit af3fecc

Browse files
committed
Consistently handle NotRetryingDestination and FederationDeniedError
1 parent 5d50eaa commit af3fecc

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

synapse/federation/federation_client.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async def _record_failure_callback(
366366
@tag_args
367367
async def get_pdu(
368368
self,
369-
destinations: Iterable[str],
369+
destinations: Collection[str],
370370
event_id: str,
371371
room_version: RoomVersion,
372372
timeout: Optional[int] = None,
@@ -389,7 +389,7 @@ async def get_pdu(
389389
"""
390390

391391
logger.debug(
392-
"get_pdu: event_id=%s from destinations=%s", event_id, destinations
392+
f"get_pdu(event_id={event_id}): from destinations=%s", destinations
393393
)
394394

395395
# TODO: Rate limit the number of times we try and get the same event.
@@ -415,11 +415,7 @@ async def get_pdu(
415415
last_attempt = pdu_attempts.get(destination, 0)
416416
if last_attempt + PDU_RETRY_TIME_MS > now:
417417
logger.debug(
418-
"get_pdu: skipping destination=%s because we tried it recently last_attempt=%s and we only check every %s (now=%s)",
419-
destination,
420-
last_attempt,
421-
PDU_RETRY_TIME_MS,
422-
now,
418+
f"get_pdu(event_id={event_id}): skipping destination={destination} because we tried it recently last_attempt={last_attempt} and we only check every {PDU_RETRY_TIME_MS} (now={now})",
423419
)
424420
continue
425421

@@ -442,25 +438,24 @@ async def get_pdu(
442438
# loop and stop asking other destinations.
443439
break
444440

445-
except SynapseError as e:
441+
except NotRetryingDestination as e:
442+
logger.info(f"get_pdu(event_id={event_id}): {e}")
443+
continue
444+
except FederationDeniedError:
446445
logger.info(
447-
"Failed to get PDU %s from %s because %s",
448-
event_id,
449-
destination,
450-
e,
446+
f"get_pdu(event_id={event_id}): Not attempting to fetch PDU from {destination} because the homeserver is not on our federation whitelist"
451447
)
452448
continue
453-
except (NotRetryingDestination, FederationDeniedError) as e:
454-
logger.info(str(e))
449+
except SynapseError as e:
450+
logger.info(
451+
f"get_pdu(event_id={event_id}): Failed to get PDU from {destination} because {e}",
452+
)
455453
continue
456454
except Exception as e:
457455
pdu_attempts[destination] = now
458456

459457
logger.info(
460-
"Failed to get PDU %s from %s because %s",
461-
event_id,
462-
destination,
463-
e,
458+
f"get_pdu(event_id={event_id}): Failed to get PDU from {destination} because {e}",
464459
)
465460
continue
466461

@@ -834,14 +829,18 @@ async def _try_destination_list(
834829
except (
835830
RequestSendFailed,
836831
InvalidResponseError,
837-
# This is the federation client retry backoff error.
838-
NotRetryingDestination,
839-
# Homeserver is not on our whitelist.
840-
FederationDeniedError,
841832
) as e:
842833
logger.warning("Failed to %s via %s: %s", description, destination, e)
843834
# Skip to the next homeserver in the list to try.
844835
continue
836+
except NotRetryingDestination as e:
837+
logger.info(f"{description}: {e}")
838+
continue
839+
except FederationDeniedError:
840+
logger.info(
841+
f"{description}: Not attempting to backfill from {destination} because the homeserver is not on our federation whitelist"
842+
)
843+
continue
845844
except UnsupportedRoomVersionError:
846845
raise
847846
except HttpResponseException as e:

synapse/handlers/federation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,14 @@ async def try_backfill(domains: Collection[str]) -> bool:
441441
# appropriate stuff.
442442
# TODO: We can probably do something more intelligent here.
443443
return True
444+
except NotRetryingDestination as e:
445+
logger.info(f"_maybe_backfill_inner: {e}")
446+
continue
447+
except FederationDeniedError:
448+
logger.info(
449+
f"_maybe_backfill_inner: Not attempting to backfill from {dom} because the homeserver is not on our federation whitelist"
450+
)
451+
continue
444452
except (SynapseError, InvalidResponseError) as e:
445453
logger.info("Failed to backfill from %s because %s", dom, e)
446454
continue
@@ -476,15 +484,9 @@ async def try_backfill(domains: Collection[str]) -> bool:
476484

477485
logger.info("Failed to backfill from %s because %s", dom, e)
478486
continue
479-
except NotRetryingDestination as e:
480-
logger.info(str(e))
481-
continue
482487
except RequestSendFailed as e:
483488
logger.info("Failed to get backfill from %s because %s", dom, e)
484489
continue
485-
except FederationDeniedError as e:
486-
logger.info(e)
487-
continue
488490
except Exception as e:
489491
logger.exception("Failed to backfill from %s because %s", dom, e)
490492
continue

synapse/util/retryutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, retry_last_ts: int, retry_interval: int, destination: str):
5151
destination: the domain in question
5252
"""
5353

54-
msg = "Not retrying server %s." % (destination,)
54+
msg = f"Not retrying server {destination} because we tried it recently retry_last_ts={retry_last_ts} and we won't check for another retry_interval={retry_interval}ms."
5555
super().__init__(msg)
5656

5757
self.retry_last_ts = retry_last_ts

0 commit comments

Comments
 (0)