Review comments

This commit is contained in:
Kegan Dougal 2020-08-19 15:37:34 +01:00
parent 5f96a859e1
commit a3c11b21c7
2 changed files with 12 additions and 1 deletions

View file

@ -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
}

View file

@ -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)))