mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Fix comment, use atomic add
This commit is contained in:
parent
b167f3c608
commit
0eee57cbea
|
|
@ -63,8 +63,7 @@ type ServerStatistics struct {
|
||||||
// failure counters. If a host was blacklisted at this point then
|
// failure counters. If a host was blacklisted at this point then
|
||||||
// we will unblacklist it.
|
// we will unblacklist it.
|
||||||
func (s *ServerStatistics) Success() {
|
func (s *ServerStatistics) Success() {
|
||||||
sentCounter := s.failCounter.Load()
|
s.successCounter.Add(1)
|
||||||
s.successCounter.Store(sentCounter + 1)
|
|
||||||
s.failCounter.Store(0)
|
s.failCounter.Store(0)
|
||||||
s.blacklisted.Store(false)
|
s.blacklisted.Store(false)
|
||||||
}
|
}
|
||||||
|
|
@ -75,9 +74,7 @@ func (s *ServerStatistics) Success() {
|
||||||
// as blacklisted.
|
// as blacklisted.
|
||||||
func (s *ServerStatistics) Failure() bool {
|
func (s *ServerStatistics) Failure() bool {
|
||||||
// Increase the fail counter.
|
// Increase the fail counter.
|
||||||
failCounter := s.failCounter.Load()
|
failCounter := s.failCounter.Add(1)
|
||||||
failCounter++
|
|
||||||
s.failCounter.Store(failCounter)
|
|
||||||
|
|
||||||
// Check that we haven't failed more times than is acceptable.
|
// Check that we haven't failed more times than is acceptable.
|
||||||
if failCounter >= FailuresUntilBlacklist {
|
if failCounter >= FailuresUntilBlacklist {
|
||||||
|
|
@ -100,8 +97,8 @@ func (s *ServerStatistics) Failure() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitUntil returns both a bool stating whether to wait, and then
|
// BackoffDuration returns both a bool stating whether to wait,
|
||||||
// if true, a duration to wait for.
|
// and then if true, a duration to wait for.
|
||||||
func (s *ServerStatistics) BackoffDuration() (bool, time.Duration) {
|
func (s *ServerStatistics) BackoffDuration() (bool, time.Duration) {
|
||||||
backoff, until := false, time.Second
|
backoff, until := false, time.Second
|
||||||
if b, ok := s.backoffUntil.Load().(time.Time); ok {
|
if b, ok := s.backoffUntil.Load().(time.Time); ok {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue