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

Commit 73ecff7

Browse files
Improve backfill robustness by trying more servers. (#13890)
Co-authored-by: Eric Eastwood <[email protected]>
1 parent 5f659d4 commit 73ecff7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

changelog.d/13890.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve backfill robustness by trying more servers when we get a `4xx` error back.

synapse/handlers/federation.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,15 @@ async def _maybe_backfill_inner(
417417

418418
async def try_backfill(domains: Collection[str]) -> bool:
419419
# TODO: Should we try multiple of these at a time?
420+
421+
# Number of contacted remote homeservers that have denied our backfill
422+
# request with a 4xx code.
423+
denied_count = 0
424+
425+
# Maximum number of contacted remote homeservers that can deny our
426+
# backfill request with 4xx codes before we give up.
427+
max_denied_count = 5
428+
420429
for dom in domains:
421430
# We don't want to ask our own server for information we don't have
422431
if dom == self.server_name:
@@ -435,13 +444,33 @@ async def try_backfill(domains: Collection[str]) -> bool:
435444
continue
436445
except HttpResponseException as e:
437446
if 400 <= e.code < 500:
438-
raise e.to_synapse_error()
447+
logger.warning(
448+
"Backfill denied from %s because %s [%d/%d]",
449+
dom,
450+
e,
451+
denied_count,
452+
max_denied_count,
453+
)
454+
denied_count += 1
455+
if denied_count >= max_denied_count:
456+
return False
457+
continue
439458

440459
logger.info("Failed to backfill from %s because %s", dom, e)
441460
continue
442461
except CodeMessageException as e:
443462
if 400 <= e.code < 500:
444-
raise
463+
logger.warning(
464+
"Backfill denied from %s because %s [%d/%d]",
465+
dom,
466+
e,
467+
denied_count,
468+
max_denied_count,
469+
)
470+
denied_count += 1
471+
if denied_count >= max_denied_count:
472+
return False
473+
continue
445474

446475
logger.info("Failed to backfill from %s because %s", dom, e)
447476
continue

0 commit comments

Comments
 (0)