From a3c11b21c7e2cae913c78c71c921b7e55d5c248d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 19 Aug 2020 15:37:34 +0100 Subject: [PATCH] Review comments --- federationsender/internal/api.go | 2 +- federationsender/statistics/statistics.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/federationsender/internal/api.go b/federationsender/internal/api.go index dd7cb63cf..386149a33 100644 --- a/federationsender/internal/api.go +++ b/federationsender/internal/api.go @@ -77,7 +77,7 @@ func failBlacklistableError(err error, stats *statistics.ServerStatistics) { stats.Failure() return } - if mxerr.Code == 500 { + if mxerr.Code >= 500 || mxerr.Code < 600 { stats.Failure() return } diff --git a/federationsender/statistics/statistics.go b/federationsender/statistics/statistics.go index 0dd8da200..07b7e7b9c 100644 --- a/federationsender/statistics/statistics.go +++ b/federationsender/statistics/statistics.go @@ -97,11 +97,22 @@ func (s *ServerStatistics) Failure() { // BackoffIfRequired will block for as long as the current // backoff requires, if needed. Otherwise it will do nothing. +// Returns the amount of time to backoff for and whether to give up or not. func (s *ServerStatistics) BackoffIfRequired(backingOff atomic.Bool, interrupt <-chan bool) (time.Duration, bool) { if started := s.backoffStarted.Load(); !started { return 0, false } + // Check if the interrupt channel is already closed. If it is + // then this call should have no side effects but still return + // the current duration. + select { + case <-interrupt: + count := s.backoffCount.Load() + return time.Second * time.Duration(math.Exp2(float64(count))), false + default: + } + // Work out how many times we've backed off so far. count := s.backoffCount.Inc() duration := time.Second * time.Duration(math.Exp2(float64(count)))