diff --git a/federationsender/federationsender.go b/federationsender/federationsender.go index 17d218c23..9e14f6ec5 100644 --- a/federationsender/federationsender.go +++ b/federationsender/federationsender.go @@ -49,8 +49,10 @@ func NewInternalAPI( } stats := &statistics.Statistics{ - DB: federationSenderDB, + DB: federationSenderDB, + FailuresUntilBlacklist: base.Cfg.Matrix.FederationMaxRetries, } + queues := queue.NewOutgoingQueues( federationSenderDB, base.Cfg.Matrix.ServerName, federation, rsAPI, stats, &queue.SigningInfo{ diff --git a/federationsender/statistics/statistics.go b/federationsender/statistics/statistics.go index 8e0be5729..5405561de 100644 --- a/federationsender/statistics/statistics.go +++ b/federationsender/statistics/statistics.go @@ -11,13 +11,6 @@ import ( "go.uber.org/atomic" ) -const ( - // How many times should we tolerate consecutive failures before we - // just blacklist the host altogether? Bear in mind that the backoff - // is exponential, so the max time here to attempt is 2**failures. - FailuresUntilBlacklist = 3 // 16 equates to roughly 18 hours. -) - // Statistics contains information about all of the remote federated // hosts that we have interacted with. It is basically a threadsafe // wrapper. @@ -25,6 +18,11 @@ type Statistics struct { DB storage.Database servers map[gomatrixserverlib.ServerName]*ServerStatistics mutex sync.RWMutex + + // How many times should we tolerate consecutive failures before we + // just blacklist the host altogether? Bear in mind that the backoff + // is exponential, so the max time here to attempt is 2**failures. + FailuresUntilBlacklist uint32 } // ForServer returns server statistics for the given server name. If it @@ -95,7 +93,7 @@ func (s *ServerStatistics) Failure() bool { failCounter := s.failCounter.Add(1) // Check that we haven't failed more times than is acceptable. - if failCounter >= FailuresUntilBlacklist { + if failCounter >= s.statistics.FailuresUntilBlacklist { // We've exceeded the maximum amount of times we're willing // to back off, which is probably in the region of hours by // now. Mark the host as blacklisted and tell the caller to diff --git a/internal/config/config.go b/internal/config/config.go index 53145efe9..6a29f52b9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -102,6 +102,11 @@ type Dendrite struct { // Perspective keyservers, to use as a backup when direct key fetch // requests don't succeed KeyPerspectives KeyPerspectives `yaml:"key_perspectives"` + // Federation failure threshold. How many consecutive failures that we should + // tolerate when sending federation requests to a specific server. The backoff + // is 2**x seconds, so 1 = 2 seconds, 2 = 4 seconds, 3 = 8 seconds, etc. + // The default value is 16 if not specified, which is circa 18 hours. + FederationMaxRetries uint32 `yaml:"federation_max_retries"` } `yaml:"matrix"` // The configuration specific to the media repostitory. @@ -479,6 +484,10 @@ func (config *Dendrite) SetDefaults() { config.Matrix.TrustedIDServers = []string{} } + if config.Matrix.FederationMaxRetries == 0 { + config.Matrix.FederationMaxRetries = 16 + } + if config.Media.MaxThumbnailGenerators == 0 { config.Media.MaxThumbnailGenerators = 10 }